Add submission script
This commit is contained in:
parent
b0012511ca
commit
1ae1950e3d
1 changed files with 47 additions and 0 deletions
47
firewall-server/prepare.sh
Normal file
47
firewall-server/prepare.sh
Normal file
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
RE='#include "([a-zA-Z\/_.]+)"'
|
||||
CFILES=$(realpath $(find -maxdepth 1 -type f -name '*.c'))
|
||||
|
||||
function deduplicate(){
|
||||
echo $1 | sed 's/ /\n/g' | sort -u -
|
||||
}
|
||||
|
||||
function check_file(){
|
||||
fname=$1
|
||||
res=$(sed -nr "s/$RE/\\1/p" $fname)
|
||||
if [[ $res != "" ]]; then
|
||||
new=$(deduplicate "$(cd $(dirname $fname) && realpath $res)")
|
||||
for x in $new
|
||||
do
|
||||
new="$new $(check_file $x)"
|
||||
done
|
||||
echo $new
|
||||
fi
|
||||
}
|
||||
|
||||
for fname in $CFILES
|
||||
do
|
||||
CFILES="$CFILES $(check_file $fname)"
|
||||
done
|
||||
|
||||
deduplicate "$CFILES"
|
||||
|
||||
tmpdir=$(mktemp --dir -p .)
|
||||
DIR=$tmpdir/ex2
|
||||
mkdir -p $DIR
|
||||
|
||||
for fname in $CFILES
|
||||
do
|
||||
bp=$(basename $fname)
|
||||
cp $fname $DIR/$bp
|
||||
sed -i -r 's/#include "[a-zA-Z.\/_]+\/([a-zA-Z_]+.c)"/#include "\1"/g' $DIR/$bp
|
||||
done
|
||||
|
||||
cp Makefile $DIR
|
||||
|
||||
(cd $tmpdir && zip -r ../ex2_submission.zip *)
|
||||
|
||||
rm -rf $tmpdir
|
Reference in a new issue