-
Notifications
You must be signed in to change notification settings - Fork 0
/
grade10
executable file
·52 lines (44 loc) · 1.11 KB
/
grade10
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
#!/usr/bin/env bash
if [[ $# -eq 0 ]]; then
echo "Parameters: [[input]] [[extras]] [file] defaults to ./input.txt] "
echo "Each line in [input] will be run individually, include newlines if needed"
exit 1
fi
# Grab arguments
file=$3
# Grab input file if provided, else assumed to be ./input.txt
if [ -z "$1" ]; then
input="./input.txt"
else
input=$1
fi
# set exec and err vars
exe=${file%.*}.out
err=${file%.*}.txt
# Removes previous error file if it exists
rm $err 2>/dev/null
code "$file" -r
# compile using gcc
# only displays erros in compiling
gcc "$file" -o "$exe" -lm >/dev/null 2>>"$err"
# Run program
cat "$input" | "./$exe" "$2" 2>> "$err"
# clean up
rm "$exe" 2>/dev/null
# delete errors if empty
RED='\033[0;31m'
GREEN='\033[0;32m'
if [ -s "$err" ]; then
echo -e "\e[31mErrors located in $err"
else
echo -e "\n\033[0;32m$file compiled and ran sucessfully"
rm "$err"
fi
# Check for 80 character limit
cat "$file" | while read line; do
count=$(echo "$line" | wc -c)
if [ $count -gt 82 ]; then
echo -e "\033[0;33mLine exceeds 80 characters"
break
fi
done