-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvicg
executable file
·57 lines (46 loc) · 1.21 KB
/
vicg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
# usage: $0 [struct] <type to search> [<member>]
## Open vim with coccigrep search, save temporary output for repeated calls
## NOTE: upstream coccigrep stopped working for some reason, this is a simpler
## version that does not find all occurrences.
para=`grep -c ^processor /proc/cpuinfo`
tmp=/tmp/coccigrep.$$$RANDOM.txt
tmpcocci=/tmp/coccigrep.$$$RANDOM.txt
memb=
stru=
if [ -z "$1" ]; then
echo "Usage: $0 struct [member] [other args to coccigrep]"
exit 1
fi
# $0 struct mystruct member
if [ "$1" = 'struct' ]; then
stru="struct $2"
shift
shift
elif [[ $1 =~ ^struct ]]; then
stru="$1"
shift
else
stru="struct $1"
shift
fi
if ! [ -z "$1" ]; then
memb="$1"
shift
fi
echo "Running coccigrep with $para jobs to $tmp"
echo "RUN: coccigrep -p $para --vim -t $stru $memb $@ *.[ch] > $tmp"
#coccigrep -p $para --vim -t "$stru" $memb "$@" *.[ch] > "$tmp"
echo "@@
$stru *STRUCT;
@@
* STRUCT->$memb" > "$tmpcocci"
cat "$tmpcocci"
spatch --quiet --jobs $para -sp_file "$tmpcocci" -dir . -include_headers -U 0 |
awk 'BEGIN{fn="NONE";ln=0;}
/^---/ { fn=$2; }
/^@@/ { ln=$2; ln=-ln; printf("%s:%d:1\n",fn,ln); }' \
> "$tmp"
rm -- "$tmpcocci"
echo "Using $tmp for results, run vim -q $tmp"
vim -q "$tmp"