xref: /illumos-gate/usr/src/tools/smatch/src/smatch_scripts/show_ifs.sh (revision 4c87aefe8930bd07275b8dd2e96ea5f24d93a52e)
1#!/bin/bash
2
3context=1
4if [ "$1" = "-C" ] ; then
5    shift
6    context=$1
7    shift
8fi
9
10file=$1
11if [[ "$file" = "" ]] ; then
12    echo "Usage:  $0 [-C <lines of context>] <file with smatch messages>"
13    exit 1
14fi
15
16grep 'if();' $file | cut -d ' ' -f1 | while read loc; do
17    code_file=$(echo $loc | cut -d ':' -f 1)
18    line=$(echo $loc | cut -d ':' -f 2)
19    echo "========================================================="
20    echo $code_file $line
21    tail -n +$(($line - ($context - 1))) $code_file | head -n $(($context - 1))
22    if [[ $context -gt 1 ]] ; then
23	echo "---------------------------------------------------------"
24    fi
25    tail -n +${line} $code_file | head -n $context
26done
27
28