-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·112 lines (105 loc) · 2.39 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
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
#!/bin/bash
# run [-x language] [-g] srcfile
# quickly build and run file
# Supported language: cxx (default), asm
while getopts "x:g" opt; do
case $opt in
x)
lang="$OPTARG"
shift 2;
;;
g)
debug=1
shift 1;
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Check for files that may be overwritten
if [[ -f temp.o || -f temp.out ]]; then
read -r -p "temp may be deleted. Proceed? (y/n)" yn
if [[ "$yn" != y ]]; then
echo "Aborting..."
exit 1
fi
fi
# Process arguments
file=$1
if [[ $file =~ ^(.+)\.([^.]+)$ ]]; then
filename="${BASH_REMATCH[1]}"
file_ext="${BASH_REMATCH[2]}"
else
filename="$file"
fi
# Assign language based on extension
if [[ "$lang" = '' ]]; then
case $file_ext in
"cpp" )
lang="cxx"
;;
"c" )
lang="c"
;;
"s" )
lang="asm"
;;
"rs" )
lang="rust"
;;
* )
echo "No valid language specified by file extension or flag"
exit 1
;;
esac
fi
case $lang in
"cxx" )
if [[ -z $CXX ]]; then CXX=g++; fi
if [[ "$debug" ]]; then
$CXX "$1" -g $CXXFLAGS -o "$filename.out"
shift 1
if [[ -z $DB ]]; then DB='gdb -tui'; fi
$DB "$filename.out"
else
$CXX "$1" $CXXFLAGS -o "$filename.out"
shift 1
./"$filename.out" "$@"
fi
rm -rf "$filename.out" "$filename.out.dSYM"
;;
"c" )
if [[ -z $CC ]]; then CC=gcc; fi
if [[ "$debug" ]]; then
$CC "$1" -g $CCFLAGS
shift 1
if [[ -z $DB ]]; then DB='gdb -tui'; fi
$DB a.out
else
$CC "$1" $CCFLAGS
shift 1
./a.out "$@"
fi
rm -rf a.out a.out.dSYM
;;
"asm" )
echo "Assembling $1..."
as --gstabs --32 -o "temp.o" "$1"
ld -melf_i386 -o "temp.out" "temp.o"
echo "Running temp.out"
gdb -tui -ex "b done" "temp.out"
read -r -p "Clean build file? (y/n)" yn
if [[ "$yn" != y ]]; then
rm -rf "temp.out" "temp.o"
exit 0
fi
;;
"rust" )
rustc $file -o "$filename.out"
./"$filename.out"
rm -rf "$filename.out"
exit 0
;;
esac