plan9fox/rc/bin/ssam
Ori Bernstein 5bc9b0c3ca improve usage messages (thanks henesy)
Fix inconsistencies between programs and their usage
messages,  correct instances where information seems
to be missing or lost. This  includes missing arguments,
making usage consistent with manuals, and so on.
2020-03-10 10:09:34 -07:00

45 lines
644 B
Bash
Executable file

#!/bin/rc
# ssam - stream interface to sam
rfork e
flagfmt='n,e script,f sfile'
args='[ file ... ]'
argv0=$0
fn usage { echo usage: $argv0 '[ -n ] [ -e script ] [ -f sfile ] [ file ... ]' >[1=2] }
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