-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganize.sh
executable file
·225 lines (164 loc) · 3.87 KB
/
organize.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
verbose=0
noexecute=0
if [[ "$#" -eq 5 && "$5" == "-noexecute" ]]
then
noexecute=1
fi
if [[ "$#" -eq 5 && "$5" == "-v" ]]
then
verbose=1
fi
if [ "$#" -eq 6 ]
then
noexecute=1
verbose=1
fi
mkdir $2
echo student_id,type,matched,not_matched > $2/result.csv
for file in $1/*
do
temp=${file%.zip}
unzip -q -j "$file" "*.c" -d "$2/${temp: -7}"
done
if [ $verbose -eq 1 ];then
echo Unzip done for C files successfully
fi
for file in $1/*
do
temp=${file%.zip}
unzip -q -j "$file" "*.java" -d "$2/${temp: -7}"
done
if [ $verbose -eq 1 ];then
echo Unzip done for java files successfully
fi
for file in $1/*
do
temp=${file%.zip}
unzip -q -j "$file" "*.py" -d "$2/${temp: -7}"
done
if [ $verbose -eq 1 ];then
echo Unzip done for python files successfully
fi
if [ $verbose -eq 1 ];then
echo Unzip done for all files successfully
fi
for file in $2/*
do
if [ -e $file/*.c ]
then
temp=`echo "$file" | cut -d "/" -f 2`
mkdir -p $2/C/$temp
mv $file/*.c $2/C/$temp/main.c
if [ $verbose -eq 1 ];then
echo Organizing files of $temp
fi
rm -r $file
fi
done
if [ $verbose -eq 1 ];then
echo .c files stored in C folder
fi
for file in $2/*
do
if [ -e $file/*.java ]
then
temp=`echo "$file" | cut -d "/" -f 2`
mkdir -p $2/Java/$temp
mv $file/*.java $2/Java/$temp/Main.java
if [ $verbose -eq 1 ];then
echo Organizing files of $temp
fi
rm -r $file
fi
done
if [ $verbose -eq 1 ];then
echo .java files stored in Java folder
fi
for file in $2/*
do
if [ -e $file/*.py ]
then
temp=`echo "$file" | cut -d "/" -f 2`
mkdir -p $2/Python/$temp
mv $file/*.py $2/Python/$temp/main.py
if [ $verbose -eq 1 ];then
echo Organizing files of $temp
fi
rm -r $file
fi
done
if [ $verbose -eq 1 ];then
echo .py files stored in Python folder
fi
if [ $verbose -eq 1 ];then
echo Task A done successfully
echo All files are organized into directories named according to their student ID
fi
# now task B
if [ $noexecute -eq 0 ]
then
for file in $2/C/*
do
no_of_matches=0
temp=`echo "$file" | cut -d "/" -f 3`
`gcc $file/main.c -o $file/main.out`
if [ $verbose -eq 1 ];then
echo Executing files of $temp
fi
for((i=1;i<=3;i++))
do
`./$file/main.out < $3/test$i.txt > $file/out$i.txt`
does_match=`diff $file/out$i.txt answers/ans$i.txt`
if [ -z "$does_match" ]
then
no_of_matches=`expr $no_of_matches + 1`
fi
done
didnt_match=`expr 3 - $no_of_matches`
echo $temp,C,$no_of_matches,$didnt_match >> $2/result.csv
done
fi
if [ $noexecute -eq 0 ]
then
for file in $2/Java/*
do
no_of_matches=0
temp=`echo "$file" | cut -d "/" -f 3`
`javac $file/Main.java`
if [ $verbose -eq 1 ];then
echo Executing files of $temp
fi
for ((i=1;i<=3;i++))
do
`java -cp $file Main < $3/test$i.txt > $file/out$i.txt`
does_match=`diff $file/out$i.txt answers/ans$i.txt`
if [ -z "$does_match" ];then
no_of_matches=`expr $no_of_matches + 1`
fi
done
didnt_match=`expr 3 - $no_of_matches`
echo $temp,Java,$no_of_matches,$didnt_match >> $2/result.csv
done
fi
if [ $noexecute -eq 0 ]
then
for file in $2/Python/*
do
no_of_matches=0
temp=`echo "$file" | cut -d "/" -f 3`
if [ $verbose -eq 1 ];then
echo Executing files of $temp
fi
for ((i=1;i<=3;i++))
do
`python3 ./$file/main.py < $3/test$i.txt > $file/out$i.txt`
does_match=`diff $file/out$i.txt answers/ans$i.txt`
if [ -z "$does_match" ];then
no_of_matches=`expr $no_of_matches + 1`
fi
done
didnt_match=`expr 3 - $no_of_matches`
echo $temp,Python,$no_of_matches,$didnt_match >> $2/result.csv
done
fi