1*1f5207b7SJohn Levon#!/bin/bash 2*1f5207b7SJohn Levon 3*1f5207b7SJohn Levoncontext=1 4*1f5207b7SJohn Levonif [ "$1" = "-C" ] ; then 5*1f5207b7SJohn Levon shift 6*1f5207b7SJohn Levon context=$1 7*1f5207b7SJohn Levon shift 8*1f5207b7SJohn Levonfi 9*1f5207b7SJohn Levon 10*1f5207b7SJohn Levonfile=$1 11*1f5207b7SJohn Levonif [[ "$file" = "" ]] ; then 12*1f5207b7SJohn Levon echo "Usage: $0 [-C <lines of context>] <file with smatch messages>" 13*1f5207b7SJohn Levon exit 1 14*1f5207b7SJohn Levonfi 15*1f5207b7SJohn Levon 16*1f5207b7SJohn Levongrep 'if();' $file | cut -d ' ' -f1 | while read loc; do 17*1f5207b7SJohn Levon code_file=$(echo $loc | cut -d ':' -f 1) 18*1f5207b7SJohn Levon line=$(echo $loc | cut -d ':' -f 2) 19*1f5207b7SJohn Levon echo "=========================================================" 20*1f5207b7SJohn Levon echo $code_file $line 21*1f5207b7SJohn Levon tail -n +$(($line - ($context - 1))) $code_file | head -n $(($context - 1)) 22*1f5207b7SJohn Levon if [[ $context -gt 1 ]] ; then 23*1f5207b7SJohn Levon echo "---------------------------------------------------------" 24*1f5207b7SJohn Levon fi 25*1f5207b7SJohn Levon tail -n +${line} $code_file | head -n $context 26*1f5207b7SJohn Levondone 27*1f5207b7SJohn Levon 28