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