#!/bin/rc

temp=/n/temp

fn usage{
	echo 'usage: pipefile [-r command] [-w command] file' >[1=2]
	exit usage
}

d=0
while(~ $d 0){
	switch($1){
	case -r
		rcmd=$2
		shift 2
	case -w
		wcmd=$2
		shift 2
	case -*
		usage
	case *
		d=1
	}
}
if(! ~ $#* 1 || ~ $rcmd '' && ~ $wcmd '')
	usage
if(~ $rcmd '')
	rcmd=cat
if(~ $wcmd '')
	wcmd=cat
file=$1

<[3]$file >[4]$file {
	bind '#|' $temp
	bind $temp/data $file
	eval $wcmd <$temp/data1 >[1=4] &
	eval $rcmd <[0=3] >$temp/data1 &
	unmount $temp
}
