shithub: bin.rc

ref: 49c1ea83f5e42094b933e462eee157063a0ae690
dir: /bin/struct/

View raw version
#!/bin/rc
rfork en
fn usage {>[1=2] echo 'usage:' $usage && exit 'usage'}
usage='struct [-s] [regex] [files]'

regex=()
files=()
search='.'
while(~ $1 -* && ! ~ $1 --){
	switch($1){
	case -s
		search='/sys/include'
	case *
		usage
	}
	shift
}
if(~ $1 --)
	shift

regex=$1
if(~ $#regex 0)
	regex='[a-zA-Z_][a-zA-Z_0-9]*'
if(test $#* -gt 1)
	files=$*(2-)
if not
	files=`{walk -f $search | grep '\.[ch]$'}

echo 'X ,x/^struct([^}][^;]*\n*)+};\n/ g/^struct[ 	]+'$regex'/ {
	!echo $%:$%l
	p
}' | sam -d $files >[2]/dev/null