shithub: bin.rc

ref: 858601ce88f1dc0d9758d101fc7ac26cfcf1c2fb
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