Blob


1 #!/usr/local/plan9/bin/rc
3 sym = 'threadmain?z
4 p9main?z
5 main?z'
7 fn dbsrc{
8 echo $sym | db $1 | 9 sed '1d;/symbol not found/d;s/.*\(\) //'
9 }
11 fn go{
12 type=`{file $1}
13 switch($type){
14 case *'script text'*
15 plumbit $1 '(script)'
16 case *executable* *'plan 9 boot image'* *'shared object'*
17 plumbit `{dbsrc $1} '(executable)'
18 case *
19 echo 'src: can''t find source for '$1 - unrecognized type $type >[1=2]
20 }
21 }
23 fn plumbit{B $1}
25 fn usage{
26 echo usage: 'src [-n] [-s symbol] executable ...'>[1=2]
27 exit usage
28 }
30 while(~ $1 -*)
31 switch($1){
32 case -n
33 shift
34 fn plumbit {echo $1}
35 case -s
36 shift
37 # add main in case symbol is undefined
38 sym=$1'?z
39 threadmain?z
40 p9main?z
41 main?z'
42 shift
43 case -*
44 usage
45 }
47 if(~ $#* 0) usage
48 ifs='
49 '
50 for(i){
51 wi=`{which $i >[2]/dev/null}
52 if(test -f $i) go $i
53 if not if(~ $#wi 1 && test -f $wi) go $wi
54 if not echo 'src: can''t find '$i
55 }