-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrade
More file actions
executable file
·55 lines (47 loc) · 1.14 KB
/
grade
File metadata and controls
executable file
·55 lines (47 loc) · 1.14 KB
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
#!/usr/bin/env bash
if [[ $# -eq 0 ]]; then
echo "Parameters: [file] [[input] defaults to ./input.txt]"
echo "Each line in [input] will be run individually, include newlines if needed"
exit 1
fi
# Grab arguments
file=$1
# Grab input file if provided, else assumed to be ./input.txt
if [ -z "$2" ]; then
input="./input.txt"
else
input=$2
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" | while read line; do
echo "$line" | "./$exe" 2>>"$err"
echo ""
done
# 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