src 869 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/rc
  2. rfork e
  3. path=(/bin/)
  4. sym = 'threadmain?z
  5. main?z'
  6. fn dbsrc{
  7. echo $sym | db $1 | sed '1d;/symbol not found/d;s/.*\(\) //'
  8. }
  9. fn go{
  10. type=`{file <$1 | sed 's/stdin: //'}
  11. switch($type){
  12. case 'rc executable file'
  13. plumbit $1 '(rc executable)'
  14. case *executable* *'plan 9 boot image'*
  15. plumbit `{dbsrc $1} '(executable)'
  16. case *
  17. echo 'src: can''t find source for '$1 - unrecognized type $type >[1=2]
  18. }
  19. }
  20. fn plumbit{B $1}
  21. fn usage{
  22. echo usage: 'src [-n] [-s symbol] executable ...'>[1=2]
  23. exit usage
  24. }
  25. while(~ $1 -*)
  26. switch($1){
  27. case -n
  28. shift
  29. fn plumbit {echo $1}
  30. case -s
  31. shift
  32. # add main in case symbol is undefined
  33. sym=$1'?z
  34. main?z'
  35. shift
  36. case -*
  37. usage
  38. }
  39. if(~ $#* 0) usage
  40. for(i){
  41. if(test -f $i) go $i
  42. if not if(test -f /bin/$i) go /bin/$i
  43. if not if(test -f /bin/*/$i) go /bin/*/$i
  44. if not echo 'src: can''t find '$i
  45. }