-
Notifications
You must be signed in to change notification settings - Fork 1
/
finderr.sh
executable file
·92 lines (74 loc) · 2.11 KB
/
finderr.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# finds location of internal error using error ID
# check for argument
if [ -z "$1" ]; then
echo "No error ID given!";
exit 1;
fi
# check if id is valid
if ! [[ "$1" =~ ^([A-Z][A-Z])([0-9]+)([A-Z])$ ]]; then
echo "Invalid error ID given!";
exit 1;
fi
id="$1";
echo "Error ID: $id";
name_start="${BASH_REMATCH[1]}";
echo " - File ID: $name_start";
line="${BASH_REMATCH[2]}";
echo " - Line: $line";
ext_start="${BASH_REMATCH[3]}";
echo " - File Type ID: $ext_start";
echo;
# find potentional files
IFS='
'
files=($(find ./src ./include -iname ${name_start,,}*.${ext_start,,}*))
IFS=' '
# if file doesnt have enough lines leave it out
to_discard=()
for (( i = 0; i < ${#files[@]}; i++ )); do
f=${files[$i]};
l=$(wc -l < "$f")
if (( $l == 0 )) || (( $l < $line )); then
echo "File $f discarded (too short)";
to_discard+=( $i );
fi
done
for i in "${to_discard[@]}"; do unset 'files[$i]'; done
if ! [ -z "${to_discard[@]}" ]; then echo; fi
# check if we found files
if [ -z "$files" ]; then
echo "Could not find file!";
exit 1;
fi
# if its just one file, choose that
if [ ${#files[@]} -eq "1" ]; then
file=${files[0]};
else
echo "Files found:"
i=1
for f in "${files[@]}"; do
found=$(echo "$(sed -n $((line ))p "$f")" | grep "INTERNAL_ERROR");
foundmsg=$([ -z "$found" ] && echo "" || echo "(found \"INTERNAL_ERROR\")");
printf " %d: %s %s\n" $i $f "$foundmsg";
i=$((i + 1));
done
printf "Enter correct file number: "
read index
while ! ((index >= 1 && index <= ${#files[@]})) 2> /dev/null; do
echo "Integers from 1 to ${#files[@]} only!"
printf "Enter correct file number: "
read index
done
file=${files[(($index - 1))]}
echo;
fi
echo "File: $file";
max=$((line + 2));
l=${#max};
echo "Source:"
printf " %${l}d│ %s\n" $((line - 2)) "$(sed -n $((line - 2))p "$file")";
printf " %${l}d│ %s\n" $((line - 1)) "$(sed -n $((line - 1))p "$file")";
printf " -> %${l}d│ %s\n" $((line )) "$(sed -n $((line ))p "$file")";
printf " %${l}d│ %s\n" $((line + 1)) "$(sed -n $((line + 1))p "$file")";
printf " %${l}d│ %s\n" $((line + 2)) "$(sed -n $((line + 2))p "$file")";