shithub: bin.rc

ref: 7888f0d7ab5dbd4f0a92cef3730590a4c7b9bea8
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