shithub: werc

Download patch

ref: 493395e39608267c5458c9cc20e0617dfd74c388
parent: 3f37f7dc50fdf85da172a9bfc349e2cd3ce83838
author: sl <sl@stanleylieber.com>
date: Wed Jun 10 16:42:38 EDT 2020

add werc/bin/ssam

--- /dev/null
+++ b/bin/ssam
@@ -1,0 +1,56 @@
+#!/bin/rc
+# ssam - stream interface to sam
+rfork e
+
+fn enosam { echo ssam: sam not found >[1=2] }
+for(i in `{whatis sam}){
+	if(test -x $i)
+		j=1
+}
+if(~ $#j 0){
+	enosam
+	exit enosam
+}
+
+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
+if(~ $#user 0)
+	user=$USER
+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