-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathpercorre_arq.sh
executable file
·146 lines (137 loc) · 2.54 KB
/
percorre_arq.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
if [ $# -lt 1 ]
then
echo Indique código-fonte a ser detalhado. Por exemplo:
echo " "\$ $0 $(ls *.c | head -1)
exit
fi
function read_key()
{
read -rsn1 ui
case "$ui" in
$'\x1b') # Handle ESC sequence.
# Flush read. We account for sequences for Fx keys as
# well. 6 should suffice far more then enough.
read -rsn1 -t 0.1 tmp
if [[ "$tmp" == "[" ]]
then
read -rsn1 -t 0.1 tmp
case "$tmp" in
"A") printf "B";; #"Up";;
"B") printf "F";; #"Down";;
"C") printf "F";; #"Right";;
"D") printf "B";; #"Left";;
esac
fi
# Flush "stdin" with 0.1 sec timeout.
read -rsn5 -t 0.1
;;
# Other one byte (char) cases. Here only quit.
q)
printf "F";
break;;
esac
}
function change_color()
{
case "$1" in
"Black")
printf '\033[0;30m';;
"Red")
printf '\033[0;31m';;
"Green")
printf '\033[0;32m';;
"Brown/Orange")
printf '\033[0;33m';;
"Blue")
printf '\033[0;34m';;
"Purple")
printf '\033[0;35m';;
"Cyan")
printf '\033[0;36m';;
"Light Gray")
printf '\033[0;37m';;
"Dark Gray")
printf '\033[1;30m';;
"Light Red")
printf '\033[1;31m';;
"Light Green")
printf '\033[1;32m';;
"Yellow")
printf '\033[1;33m';;
"Light Blue")
printf '\033[1;34m';;
"Light Purple")
printf '\033[1;35m';;
"Light Cyan")
printf '\033[1;36m';;
"White")
printf '\033[1;37m';;
"No color")
printf '\033[0m';;
esac
}
function aviso()
{
change_color "Blue"
N_AVISO=${#1}
N_AVISO=$((N_AVISO + 8))
LINHA_AVISO=""
for n in $(seq $N_AVISO)
do
LINHA_AVISO=${LINHA_AVISO}'='
done
echo ${LINHA_AVISO}
echo "===" $1 "==="
echo ${LINHA_AVISO}
echo
change_color "No color"
}
DELIM="SOE"
N=$(wc -l < $1)
LINHAS=($(grep ${DELIM} -n $1 | grep -oP "^.*?(?=\:)"))
XTRA=($(grep -oP "(?<=${DELIM}\().*?(?=\))" $1))
SED_SEARCH="s/${DELIM}\([0-9]*\)//"
i=1
while [ $i -le ${#LINHAS[@]} ]
do
l=${LINHAS[$((i-1))]}
k=${XTRA[$((i-1))]}
clear
aviso $1
if [ ${l} -gt 1 ]
then
head -$((l-1)) $1 | sed -r "${SED_SEARCH}"
fi
change_color "Red"
head -${l} $1 | tail -1 | sed -r "${SED_SEARCH}"
change_color "Yellow"
head -$((l+k)) $1 | tail -${k} | sed -r "${SED_SEARCH}"
change_color "No color"
NLK=$((N-l-k))
if [ ${NLK} -gt 0 ]
then
tail -${NLK} $1 | sed -r "${SED_SEARCH}"
fi
echo
if [ $(read_key) == "B" ]
then
if [ ${i} -gt 1 ]
then
i=$((i-1))
fi
else
i=$((i+1))
fi
done
clear
aviso $1
cat $1 | sed -r "${SED_SEARCH}"
echo
aviso "Compilação do código"
EXEC_1=${1%.?}.out
make ${EXEC_1}
echo
aviso "Código executado"
./${EXEC_1}
rm ${EXEC_1}