]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ||
3 | ||
4 | show_name=0 | |
5 | show_ver=0 | |
6 | show_arch=0 | |
7 | show_default=1 | |
8 | fname="" | |
9 | ||
10 | usage="usage: $0 [option]... <cls_filename>\n" | |
11 | usage=$usage"options:\n" | |
12 | usage=$usage"\t-n, --name\n" | |
13 | usage=$usage"\t-v, --ver\n" | |
14 | usage=$usage"\t-a, --arch\n" | |
15 | ||
16 | usage_exit() { | |
17 | printf "$usage" | |
18 | exit 1 | |
19 | } | |
20 | ||
21 | err_exit() { | |
22 | echo "Error: $*" | |
23 | exit 1 | |
24 | } | |
25 | ||
26 | while [ $# -ge 1 ]; do | |
27 | case $1 in | |
28 | -n | --name ) | |
29 | show_name=1 | |
30 | show_default=0 | |
31 | ;; | |
32 | -v | --ver ) | |
33 | show_ver=1 | |
34 | show_default=0 | |
35 | ;; | |
36 | -a | --arch ) | |
37 | show_arch=1 | |
38 | show_default=0 | |
39 | ;; | |
40 | * ) | |
41 | [ -n "$fname" ] && usage_exit | |
42 | fname=$1 | |
43 | ;; | |
44 | ||
45 | esac | |
46 | shift | |
47 | done | |
48 | ||
49 | [ -z "$fname" ] && usage_exit | |
50 | ||
51 | if [ $show_default -eq 1 ]; then | |
52 | show_name=1 | |
53 | show_ver=1 | |
54 | show_arch=1 | |
55 | fi | |
56 | ||
57 | [ -e "$fname" ] || err_exit "File not found: ${fname}" | |
58 | ||
59 | if [ $show_name -eq 1 ]; then | |
60 | raw_name=`nm $fname | grep __cls_name__` | |
61 | name=`echo $raw_name | sed 's/.*cls_name__//g'` | |
62 | [ -z "$name" ] && err_exit "Could not detect class name" | |
63 | s=$name | |
64 | c=" " | |
65 | fi | |
66 | ||
67 | if [ $show_ver -eq 1 ]; then | |
68 | raw_ver=`nm $fname | grep __cls_ver__` | |
69 | ver=`echo $raw_ver | sed 's/.*cls_ver__//g; s/_/./g'` | |
70 | [ -z "$ver" ] && err_exit "Could not detect class version" | |
71 | s=$s$c$ver | |
72 | c=" " | |
73 | fi | |
74 | ||
75 | if [ $show_arch -eq 1 ]; then | |
76 | raw_arch=`readelf -h $fname | grep Machine` | |
77 | arch="" | |
78 | [ `echo $raw_arch | grep -c 386` -gt 0 ] && arch="i386" | |
79 | [ `echo $raw_arch | grep -c 86-64` -gt 0 ] && arch="x86-64" | |
80 | [ -z "$arch" ] && err_exit "unknown file architecture" | |
81 | s=$s$c$arch | |
82 | c=" " | |
83 | fi | |
84 | ||
85 | echo $s |