9base

revived minimalist port of Plan 9 userland to Unix
git clone git://git.suckless.org/9base
Log | Files | Refs | README | LICENSE

ssam (551B)


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