-
Notifications
You must be signed in to change notification settings - Fork 0
/
febug.sh
275 lines (227 loc) · 5.28 KB
/
febug.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/bash
#
# Created by Muhammad Faishol Amirul Mukminin on 17/05/17 07:32 PM
# Copyright (c) 2017. All rights reserved.
#
# Last modified 24/05/17 12:33 AM
#
usage(){
echo "Usage: febug <SOURCE CODE> [MODE]"
echo ""
echo "[MODE]"
echo " -c compile and run only. Input using STDIN."
echo " -i<x> Output format:"
echo " -i interactive mode with default judger."
echo " -i=<FILE> interactive mode with custom judger."
echo ""
echo " -n<x> Output format:"
echo " -n normal mode. Input using FILE."
echo " -n=<FILE> normal mode. Input using custom FILE."
echo " -n=<FOLDER> normal mode. Input using all files in FOLDER."
echo ""
echo "MODE will use '-n' for the default."
footer
exit 0
}
compile(){
echo "================"
echo "| Compiling... |"
echo "================"
#Get code language from file extention
if [[ $file == *".cpp" || $file == *".c" ]]
then
if [[ $file == *".cpp" ]]; then
file=${file/.cpp/}
stt=$( g++ $file.cpp -o $file -std=c++11 -O2 2>&1 | tee _STT_ )
else
file=${file/.c/}
stt=$( g++ $file.c -o $file -std=c++11 -O2 2>&1 | tee _STT_ )
fi
cat _STT_
rm _STT_
if [[ $stt == *"error:"* ]]; then
echo ""
echo "[ERROR] Compilation Error"
footer
exit 0
fi
elif [[ $file == *".pas" ]]
then
file=${file/.pas/}
stt=$( fpc $file.pas -o $file -O2 2>&1 | tee _STT_ )
cat _STT_
rm _STT_
if [[ $stt == *"error exitcode"* ]]; then
echo ""
echo "[ERROR] Compilation Error"
footer
exit 0
fi
else
clear
echo "[ERROR] Invalid source code"
footer
exit 0
fi
if [ "$mode" == '-i' ]
then
if [[ $judge == *".cpp" || $judge == *".c" ]]
then
if [[ $judge == *".cpp" ]]; then
judge=${judge/.cpp/}
stt=$( g++ $judge.cpp -o $judge -std=c++11 -O2 2>&1 | tee _STT_ )
else
judge=${judge/.c/}
stt=$( g++ $judge.c -o $judge -std=c++11 -O2 2>&1 | tee _STT_ )
fi
cat _STT_
rm _STT_
if [[ $stt == *"error"* ]]; then
echo ""
echo "[ERROR] Compilation Error"
footer
exit 0
fi
elif [[ $judge == *".pas" ]]
then
judge=${judge/.pas/}
stt=$( fpc $judge.pas -o $judge -O2 2>&1 | tee _STT_ )
cat _STT_
rm _STT_
if [[ $stt == *"error exitcode"* ]]; then
echo ""
echo "[ERROR] Compilation Error"
footer
exit 0
fi
else
clear
echo "[ERROR] Invalid source code"
footer
exit 0
fi
fi
echo "================"
echo "| Compile Done |"
echo "================"
}
run_program(){
echo "==================="
echo "| RUNNING PROGRAM |"
echo "==================="
if [ "$mode" == '-c' ]; then
echo "============START PROGRAM============"
./$file
echo "=============END PROGRAM============="
elif [ "$mode" == '-i' ]; then
stt=$( file $file.in )
if [[ $stt == *"cannot"* ]]; then
echo "[ERROR] Missing or invalid input file"
footer
exit 0
fi
mkfifo pipa1 pipa2
cat $file.in > pipa1 | ./$judge < pipa1 | tee pipa2 >> $file.tmp | ./$file < pipa2 | tee pipa1 >> $file.tmp
rm pipa1 pipa2
echo "============START INTERACTION============"
cat $file.tmp | tee $file.out
rm $file.tmp
echo "=============END INTERACTION============="
echo ""
cat verdict
rm verdict
else
stt=$( file $file.in )
if [[ $stt == *"cannot"* ]]; then
echo "[ERROR] Missing or invalid input file"
footer
exit 0
fi
if [ "$n_args" == 'file' ]; then
#If file
{ time ./$file < $inp_file > $out_file ; } 2> waktu
echo "============START OUTPUT============"
cat $out_file
echo "=============END OUTPUT============="
echo "================"
echo "| RUNNING TIME |"
echo "================"
#Show command running time
cat waktu
rm waktu
else
ls $path > _FBG_
while read -r inp
do
stt=$( file $path/$inp )
if [[ $stt == *"ASCII text"* ]]; then
out=${inp/.in/.out}
out=${out/.txt/.out}
if [[ $inp == *".in" || $inp == *".txt" ]]; then
echo "Processing "$path/$inp
./$file < $path/$inp > $path/$out
echo "Finished with output "$path/$out
fi
fi
done < _FBG_
rm _FBG_
fi
fi
echo ""
echo "Your program running successfully"
}
footer(){
echo ""
echo ""
echo " FeBug version 1.3.2"
echo " Developed by Muhammad Faishol Amirul Mukminin"
}
# MAIN PROGRAM
file=$1
mode=$2
judge=${file/./.judge.}
n_args=file
path=
inp_file=${file/.cpp/.in}
inp_file=${inp_file/.c/.in}
inp_file=${inp_file/.pas/.in}
out_file=${inp_file/.in/.out}
if [ $# -lt 1 ]; then
usage
fi
if (( $# == 2 )); then
if [[ $mode != "-i"* && $mode != "-n"* && "$2" != '-c' ]]; then
echo "[ERROR] Invalid mode"
footer
exit 0
else
if [[ $mode == "-i="* ]]
then
judge=${mode/-i=/}
mode=-i
elif [[ $mode == "-n="* ]]
then
n_args=${mode/-n=/}
stt=$( file $n_args )
if [[ $stt == *"cannot"* ]]; then
echo "[ERROR] "$stt
footer
exit 0
elif [[ $stt == *"directory"* ]]; then
path=$n_args
n_args=folder
elif [[ $n_args == *".in" || $n_args == *".txt" ]]; then
inp_file=$n_args
out_file=${inp_file/.in/.out}
out_file=${out_file/.txt/.out}
n_args=file
fi
mode=-n
fi
fi
fi
clear
compile
run_program
footer
#END MAIN PROGRAM