fast method_name->source_file lookups, heuristics for finding ioctl names
[moctel.git] / get_ioctl_names.sh
1 #!/bin/sh
2
3 # Invocation: ./get_macro_value.sh <kernel_src> <method_list_file> <method_symbol>
4 kernel_src="$1"
5 method_list_file="$2"
6 method_symbol="$3"
7
8 if [ $# -ne 3 ]; then
9   echo "bad invocation"
10   exit 1
11 fi
12
13 if [ ! -d "$kernel_src" ]; then
14   echo "error: $kernel_src is not a directory"
15   exit 1
16 fi
17
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"
22   exit 1
23 fi
24 echo "$symbol_file"
25 if [ "$(echo "$symbol_file"|wc -l)" -gt 1 ]; then
26   echo "error: too many hits"
27   exit 1
28 fi
29 cd "$kernel_src"
30 grep_res="$(grep -R -n "\(^\| \)$method_symbol *\($\|(\)" "$symbol_file")"
31 if [ -z "$grep_res" ]; then
32   echo "error: can't find method in source"
33   exit 1
34 fi
35 echo "$grep_res"
36 if [ "$(echo "$grep_res"|wc -l)" -gt 1 ]; then
37   echo "error: too many results"
38 fi
39 symbol_line="$(echo "$grep_res" | cut -d':' -f1)"
40 echo "symbol is in $symbol_file, line $symbol_line"
41
42 # now isolate the method's code
43 partial_symbol_file="$(cat "$symbol_file" | tail -n "+$symbol_line")"
44 symbol_lines="$(echo "$partial_symbol_file" | grep -n '^}' | head -n 1 | cut -d':' -f1)"
45 echo "symbol is $symbol_lines lines long"
46 symbol_code="$(echo "$partial_symbol_file" | head -n "$symbol_lines")"
47 echo "dumping symbol code:"
48 echo ""
49 echo "$(echo "$symbol_code" | sed 's|^|        |g')"
50 echo ""
51
52 # grep for case statements
53 case_exprs="$(echo "$symbol_code" | grep 'case  *[a-zA-Z0-9_]*:' | sed 's|.*case  *\([a-zA-Z0-9_]*\):.*|\1|g')"
54 echo "ioctls found: $(echo "$case_exprs" | tr '\n' ' ')"
55