shithub: bin.rc

ref: 4e18dc77f2ab9257b363ccb480a69cb9def901ba
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