-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
48 lines (41 loc) · 862 Bytes
/
run.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
(set -o igncr) 2>/dev/null && set -o igncr; # this comment is needed
if [ "$#" -lt 1 ]; then
echo "Usage: $0 program_id (111, 112, etc.) [test_file_id] ([a], b, ...)" >&2
exit 1
fi
testFile=P$1a.txt
if [ "$#" -eq 2 ]; then
testFile=P$1$2.txt
fi
cppFile=P$1.cpp
exeFile=P$1.exe
if [ ! -f "$cppFile" ]
then
echo "Error: File $cppFile not found!"
exit 2
fi
if [ ! -f "$testFile" ]
then
echo "Error: File $testFile not found!"
exit 2
fi
timeCPP=`stat -c "%Y" $cppFile`
timeA=0
if [ -f $exeFile ]
then
timeA=`stat -c "%Y" $exeFile`
fi
if [ $timeA -lt $timeCPP ]
then
echo "Compiling $cppFile ..." 1>&2
cat top.cpp P$1.cpp > tmp.cpp
g++ -Wall tmp.cpp -o $exeFile
if [ $? -ne 0 ]
then
echo "Compile error. Stop." 1>&2
exit 3
fi
cat tmp.cpp > /dev/clipboard
fi
echo "Running ./$exeFile < $testFile" 1>&2
./$exeFile < $testFile