X-Git-Url: http://git.thejh.net/?p=moctel.git;a=blobdiff_plain;f=get_ioctl_names.sh;fp=get_ioctl_names.sh;h=7fe9fffa4d7cc1c99d524f6cc77e63050fb5729a;hp=0000000000000000000000000000000000000000;hb=73d712f1a25728984f7f9b81d7c3d02694648b4f;hpb=d20cca0688694acb09484232ada3aa4d13ac0954 diff --git a/get_ioctl_names.sh b/get_ioctl_names.sh new file mode 100755 index 0000000..7fe9fff --- /dev/null +++ b/get_ioctl_names.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# Invocation: ./get_macro_value.sh +kernel_src="$1" +method_list_file="$2" +method_symbol="$3" + +if [ $# -ne 3 ]; then + echo "bad invocation" + exit 1 +fi + +if [ ! -d "$kernel_src" ]; then + echo "error: $kernel_src is not a directory" + exit 1 +fi + +# first search for the file containing the symbol +symbol_file="$(grep "[,:]$method_symbol\(,\|$\)" "$method_list_file" | cut -d':' -f1)" +if [ -z "$symbol_file" ]; then + echo "error: can't find method in method list file" + exit 1 +fi +echo "$symbol_file" +if [ "$(echo "$symbol_file"|wc -l)" -gt 1 ]; then + echo "error: too many hits" + exit 1 +fi +cd "$kernel_src" +grep_res="$(grep -R -n "\(^\| \)$method_symbol *\($\|(\)" "$symbol_file")" +if [ -z "$grep_res" ]; then + echo "error: can't find method in source" + exit 1 +fi +echo "$grep_res" +if [ "$(echo "$grep_res"|wc -l)" -gt 1 ]; then + echo "error: too many results" +fi +symbol_line="$(echo "$grep_res" | cut -d':' -f1)" +echo "symbol is in $symbol_file, line $symbol_line" + +# now isolate the method's code +partial_symbol_file="$(cat "$symbol_file" | tail -n "+$symbol_line")" +symbol_lines="$(echo "$partial_symbol_file" | grep -n '^}' | head -n 1 | cut -d':' -f1)" +echo "symbol is $symbol_lines lines long" +symbol_code="$(echo "$partial_symbol_file" | head -n "$symbol_lines")" +echo "dumping symbol code:" +echo "" +echo "$(echo "$symbol_code" | sed 's|^| |g')" +echo "" + +# grep for case statements +case_exprs="$(echo "$symbol_code" | grep 'case *[a-zA-Z0-9_]*:' | sed 's|.*case *\([a-zA-Z0-9_]*\):.*|\1|g')" +echo "ioctls found: $(echo "$case_exprs" | tr '\n' ' ')" +