-
Notifications
You must be signed in to change notification settings - Fork 2
/
bash config.sh
96 lines (82 loc) · 1.67 KB
/
bash config.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
#copy first argument to clipborad ! ONLY WORK ON XORG !
alias clip="xclip -sel clip"
# compile the $1 parameter, if a $2 is provided
# the name will be the the binary output, if
# none is provided the binary name will be
# 'a.out'
comp() {
echo ">> COMPILING $1 <<" 1>&2
if [ $# -gt 1 ]; then
outfile="${2}"
else
outfile="a.out"
fi
time g++ -std=c++20 \
-O2 \
-g3 \
-Wall \
-fsanitize=address,undefined \
-fno-sanitize-recover \
-D LOCAL \
-o "${outfile}" \
"$1"
if [ $? -ne 0 ]; then
echo ">> FAILED <<" 1>&2
return 1
fi
echo ">> DONE << " 1>&2
}
# run the binary given in $1, if none is
# given it will try to run the 'a.out'
# binary
run() {
to_run=./a.out
if [ -n "$1" ]; then
to_run="$1"
fi
time $to_run
}
# just comp and run your cpp file
# accpets <in1 >out and everything else
comprun() {
comp "$1" "a" && run ./a ${@:2}
}
testall() {
comp "$1" generator
comp "$2" brute
comp "$3" main
input_counter=1
while true; do
echo "$input_counter"
run ./generator >input
run ./main <input >main_output.txt
run ./brute <input >brute_output.txt
diff brute_output.txt main_output.txt
if [ $? -ne 0 ]; then
echo "Outputs differ at input $input_counter"
echo "Brute file output:"
cat brute_output.txt
echo "Main file output:"
cat main_output.txt
echo "input used: "
cat input
break
fi
((input_counter++))
done
}
touch_macro() {
cat "$1"/template.cpp >>"$2"
cat "$1"/run.cpp >>"$2"
cp "$1"/debug.cpp .
}
# Creates a contest with hame $2
# Copies the macro and debug file from $1
# Already creates files a...z .cpp and .py
prepare_contest() {
mkdir "$2"
cd "$2"
for i in {a..z}; do
touch_macro $1 $i.cpp
done
}