show_unreachable.sh: change the line number format
[smatch.git] / smatch_scripts / show_unreachable.sh
blob5341cd76a303d97917fd24b771a66a2528a4d964
1 #!/bin/bash
3 context=6
4 while true ; do
5 if [ "$1" = "-C" ] ; then
6 shift
7 context=$1
8 shift
9 continue
11 if [ "$1" = "-k" ] ; then
12 shift
13 mode=kernel
14 continue
16 if [ "$1" = "-b" ] ; then
17 shift
18 nobreak=yes
19 continue
21 break
22 done
25 file=$1
26 if [[ "$file" = "" ]] ; then
27 echo "Usage: $0 [-C <lines>] [-b] [-k] <file with smatch messages>"
28 echo " -C <lines>: Print <lines> of context"
29 echo " -b : Ignore unreachable break statements"
30 echo " -k : Ignore some kernel defines"
31 exit 1
34 grep 'ignoring unreachable' $file | cut -d ' ' -f1 | while read loc; do
35 code_file=$(echo $loc | cut -d ':' -f 1)
36 line=$(echo $loc | cut -d ':' -f 2)
38 if [ "$mode" = "kernel" ] ; then
39 # BUG() is sometimes defined away on embedded systems
40 if tail -n +$(($line - 1)) $code_file | head -n 1 | \
41 egrep -qw '(BUG|BT_STATE_CHANGE)' ; then
42 continue;
44 if tail -n +$(($line)) $code_file | head -n 1 | \
45 egrep -qw '(DLM_ASSERT|BT_SI_SM_RETURN|BT_STATE_CHANGE|PARSE_ERROR1|PARSE_ERROR|CMDINSIZE|PROCESS_SYSTEM_PARAM|RETURN_STATUS|ar9170_regwrite_result)' ; then
46 continue;
50 if [ "$nobreak" = "yes" ] ; then
51 if tail -n +$(($line)) $code_file | head -n 1 | grep -qw 'break' ; then
52 continue;
56 echo "========================================================="
57 echo $code_file:$line
58 tail -n +$(($line - ($context - 1))) $code_file | head -n $(($context - 1))
59 echo "---------------------------------------------------------"
60 tail -n +${line} $code_file | head -n $context
61 done