plan9fox/rc/bin/ssam

44 lines
624 B
Text
Raw Normal View History

2011-10-23 01:01:07 +00:00
#!/bin/rc
2015-03-17 03:42:58 +00:00
rfork e
2011-10-23 01:01:07 +00:00
# ssam - stream interface to sam
flagfmt='n,e script,f sfile'
args='[ file ... ]'
2012-11-10 21:24:58 +00:00
fn usage { echo $0 '[ -n ] [ -e script ] [ -f sfile ] [ file ... ]' >[1=2] }
2011-10-23 01:01:07 +00:00
if(! ifs=() eval `{aux/getflags $*}){
usage
exit usage
}
if(~ $#flage 0 && ~ $#flagf 0) {
if(~ $#* 0) {
usage
exit usage
}
flage=$1
shift
}
if(~ $#TMPDIR 0)
TMPDIR=/tmp
tmp=$TMPDIR/ssam.tmp.$user.$pid
cat $* >$tmp
{
# select entire file
echo ',{'
echo k
echo '}'
echo 0k
# run scripts, print
if(! ~ $#flagf 0)
cat $flagf
if(! ~ $#flage 0)
echo $flage
if(~ $#flagn 0)
echo ,
} | sam -d $tmp >[2]/dev/null
rm -f $tmp