shithub: bin.rc

ref: c240c428481aa4cd9aadeb95833161b52efc1e96
dir: /bin/func/

View raw version
#!/bin/rc
# func - find C function definitions
# func [pattern]

rfork e

fn sigint sighup sigexit {
	rm -f $matches
	exit
}

ignore='(\.root.s$)|(cmd/python/)'
matches=/tmp/matches.$pid
ident='([a-zA-Z_][a-zA-Z_0-9]*)'

func=$1
func=`{echo $func | sed 's,%,'$ident'?,g'}
if(~ $#func 0)
	func=$ident
#patt='^([^ 	]+[ 	]+)*'$func'\('
patt='^'$func'\('

srcs=`{walk -f | grep '\.[chs]$' | grep -v $ignore}
>$matches grep -n $patt $srcs /dev/null
n=`{wc -l $matches}
switch($n(1)){
	case 0
		exit 'no match'
	case 1
		plumb `{<$matches sed 's,: .*,,'}
		exit
	case *
		window -m 'cat '$matches'; cat'
		sleep 1
}