aboutsummaryrefslogtreecommitdiff
path: root/bin/src
blob: bedb9f9ab753443fdbac135b5ea487915e0a9d50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/local/plan9/bin/rc

. 9.rc
sym = 'threadmain?z
	p9main?z
	main?z'

fn dbsrc{
	echo $sym | db $1 >[2]/dev/null | 9 sed '/symbol not found/d;s/.*\(\) //'
}

fn go{
	type=`{9 file $1}
	switch($type){
	case *script*
		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=`{whatis $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
}