3 # Invocation: ./get_macro_value.sh <kernel_src> <method_list_file> <method_symbol>
13 if [ ! -d "$kernel_src" ]; then
14 echo "error: $kernel_src is not a directory"
18 # first search for the file containing the symbol
19 symbol_file="$(grep "[,:]$method_symbol\(,\|$\)" "$method_list_file" | cut -d':' -f1)"
20 if [ -z "$symbol_file" ]; then
21 echo "error: can't find method in method list file"
25 if [ "$(echo "$symbol_file"|wc -l)" -gt 1 ]; then
26 echo "error: too many hits"
30 grep_res="$(grep -R -n "^\(\|\S.* \)$method_symbol *\($\|(\)" "$symbol_file")"
31 if [ -z "$grep_res" ]; then
32 echo "error: can't find method in source"
36 if [ "$(echo "$grep_res"|wc -l)" -gt 1 ]; then
37 echo "error: too many results"
40 symbol_line="$(echo "$grep_res" | cut -d':' -f1)"
41 echo "symbol is in $symbol_file, line $symbol_line"
43 # now isolate the method's code
44 partial_symbol_file="$(cat "$symbol_file" | tail -n "+$symbol_line")"
45 symbol_lines="$(echo "$partial_symbol_file" | grep -n '^}' | head -n 1 | cut -d':' -f1)"
46 echo "symbol is $symbol_lines lines long"
47 symbol_code="$(echo "$partial_symbol_file" | head -n "$symbol_lines")"
48 echo "dumping symbol code:"
50 echo "$(echo "$symbol_code" | sed 's|^| |g')"
53 # grep for case statements
54 case_exprs="$(echo "$symbol_code" | grep 'case *[a-zA-Z0-9_]*:' | sed 's|.*case *\([a-zA-Z0-9_]*\):.*|\1|g')"
55 echo "ioctls found: $(echo "$case_exprs" | tr '\n' ' ')"