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);
-}
