This repository has been archived on 2025-07-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
ossp/firewall-server/prepare.sh
2023-11-12 00:54:43 +00:00

47 lines
No EOL
877 B
Bash

#!/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