forked from X16Community/x16-rom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
findsymbols
executable file
·70 lines (61 loc) · 1.16 KB
/
findsymbols
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
#Help message
usage () {
echo "Usage: findsymbols file [-p prefix] symbol ..."
echo " file:"
echo " Symbol file created with the -Ln option in ld65"
echo " -p prefix:"
echo " A prefix added to all returned symbol names"
echo " symbol:"
echo " Name of one or more symbols"
exit 1
}
#Validate input
if [ $# -lt 2 ]; then
usage
fi
if [[ ! -f $1 ]]; then
echo "File not found"
usage
fi
#Get symbol names from command line parameters
args=($@)
unset args[0] #Delete file
#Look for optional prefix
prefix=""
prefixFound=0
index=$#
while [ $index -gt 0 ]; do
index=$(($index-1))
if [[ ${args[$index]} == "-p" ]]; then
prefixFound=1
unset args[$(($index+1))]
unset args[$index]
elif [ $prefixFound -eq 0 ]; then
prefix=${args[$index]}
fi
done
if [ $prefixFound -eq 0 ]; then
prefix=""
fi
#Parse file with awk
cat $1 |
awk -v prefix=$prefix -v args="$(IFS=:;echo "${args[*]}")" '
BEGIN {
split(args, symbols, ":");
}
{
for (s in symbols) {
if (symbols[s] == substr($3,2)) {
output[symbols[s]] = "$" substr($2,3)
}
}
}
END {
for (s in output) {
printf "-D " prefix s "=" output[s] " ";
}
printf("\n");
}
'
exit 0