aboutsummaryrefslogtreecommitdiff
path: root/bin/src
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-04-20 17:54:04 +0000
committerrsc <devnull@localhost>2004-04-20 17:54:04 +0000
commitba03b8910dd07511378e6f1007faf0539ed25598 (patch)
tree6c6fc163171b203c5549eb547e7cd9442d6b0636 /bin/src
parentdddc2ed156bd5a089b737d9abfd97820b4b0dc17 (diff)
downloadplan9port-ba03b8910dd07511378e6f1007faf0539ed25598.tar.gz
plan9port-ba03b8910dd07511378e6f1007faf0539ed25598.tar.bz2
plan9port-ba03b8910dd07511378e6f1007faf0539ed25598.zip
How could I forget this?
Diffstat (limited to 'bin/src')
-rwxr-xr-xbin/src55
1 files changed, 55 insertions, 0 deletions
diff --git a/bin/src b/bin/src
new file mode 100755
index 00000000..046417a0
--- /dev/null
+++ b/bin/src
@@ -0,0 +1,55 @@
+#!/usr/local/plan9/bin/rc
+
+sym = 'threadmain?z
+ p9main?z
+ main?z'
+
+fn dbsrc{
+ echo $sym | db $1 | 9sed '1d;/symbol not found/d;s/.*\(\) //'
+}
+
+fn go{
+ type=`{file $1}
+ switch($type){
+ case *'script text'*
+ plumbit $1 '(script)'
+ case *executable* *'plan 9 boot image'* *'shared object'*
+ plumbit `{dbsrc $1} '(executable)'
+ case *
+ echo 'src: can''t find source for '$1 - unrecognized type $type >[1=2]
+ }
+}
+
+fn plumbit{B $1}
+
+fn usage{
+ echo usage: 'src [-n] [-s symbol] executable ...'>[1=2]
+ exit usage
+}
+
+while(~ $1 -*)
+ switch($1){
+ case -n
+ shift
+ fn plumbit {echo $1}
+ case -s
+ shift
+ # add main in case symbol is undefined
+ sym=$1'?z
+ threadmain?z
+ p9main?z
+ main?z'
+ shift
+ case -*
+ usage
+ }
+
+if(~ $#* 0) usage
+ifs='
+'
+for(i){
+ wi=`{which $i >[2]/dev/null}
+ if(test -f $i) go $i
+ if not if(~ $#wi 1 && test -f $wi) go $wi
+ if not echo 'src: can''t find '$i
+}