-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·81 lines (69 loc) · 1.13 KB
/
run
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
#! /bin/sh
usage() {
echo "Usage: $0 <path-to-source-file>";
exit 1;
}
run_c() {
gcc -o $filename.out $1;
./$filename.out;
}
run_cpp() {
g++ -o $filename.out $1;
./$filename.out
}
run_python() {
python3 $1;
}
run_kotlin() {
kotlinc $1 -include-runtime -d $filename.jar;
java -jar $filename.jar;
}
run_haskell() {
# use haskell interpreter instead of compiling
runhaskell $1;
}
run_scala() {
# use scala interpreter instead of compiling
scala $1;
}
run_java() {
javac $1
cd $(dirname $1);
java $filename;
}
if [ $# -ne 1 ]; then
usage;
fi
if [ ! -f $1 ]; then
echo "Error: $1 is not a file";
usage;
fi
# Separate the filename from its extension
filename=$(basename $1);
extension="${filename##*.}";
case $extension in
"c")
run_c $1
;;
"cpp")
run_cpp $1
;;
"py")
run_python $1;
;;
"kt")
run_kotlin $1;
;;
"hs")
run_haskell $1;
;;
"sc")
run_scala $1;
;;
"java")
run_java $1;
;;
*)
echo "Unknown file type";
;;
esac