]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/ssam
/lib/rob: Just write the code.
[plan9front.git] / rc / bin / ssam
1 #!/bin/rc
2 # ssam - stream interface to sam
3
4 flagfmt='n,e script,f sfile'
5 args='[ file ... ]'
6 fn usage { echo $0 '[ -n ] [ -e script ] [ -f sfile ] [ file ... ]' >[1=2] }
7 if(! ifs=() eval `{aux/getflags $*}){
8         usage
9         exit usage
10 }
11
12 if(~ $#flage 0 && ~ $#flagf 0) {
13         if(~ $#* 0) {
14                 usage
15                 exit usage
16         }
17         flage=$1
18         shift
19 }
20
21 if(~ $#TMPDIR 0)
22         TMPDIR=/tmp
23 tmp=$TMPDIR/ssam.tmp.$user.$pid
24 cat $* >$tmp
25
26 {
27         # select entire file
28         echo ',{'
29         echo k
30         echo '}'
31         echo 0k
32
33         # run scripts, print
34         if(! ~ $#flagf 0)
35                 cat $flagf
36         if(! ~ $#flage 0)
37                 echo $flage
38         if(~ $#flagn 0)
39                 echo ,
40 } | sam -d $tmp >[2]/dev/null
41
42 rm -f $tmp