shithub: bin.rc

ref: e467b6f5ab07f5bea9049d1cb5f61d8d3846928b
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