LuPPC/scripts/txt2c
2016-01-04 18:22:01 +01:00

53 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# $1 scripts folder
# $2 file to generate OUTPUTH C
# $3 file to generate OUTPUTH H
# $4 prefix
generate() {
LUAFILES="$1/*"
OUTPUTH="$2"
OUTPUTC="$3"
PREFIX="$4"
outname="$(basename "$OUTPUTH")"
outname="${outname%.*}"
guard=$(echo "$outname" | tr '[:lower:]' '[:upper:]')
guard="$guard""_H"
for file in $LUAFILES
do
filename="$(basename "$file")"
if [ -d "$file" ]
then
generate $file $2 $3 ${PREFIX}${filename}_
else
filename="${filename%.*}"
echo "extern char $PREFIX$filename[];" >> "$OUTPUTH"
echo "char $PREFIX$filename[] = {" >> "$OUTPUTC"
echo " " $(xxd -i < "$file") ",0x00" >> "$OUTPUTC"
echo "};" >> "$OUTPUTC"
fi
done
}
OUTPUTH="$2"
outname="$(basename "$OUTPUTH")"
outname="${outname%.*}"
guard=$(echo "$outname" | tr '[:lower:]' '[:upper:]')
guard="$guard""_H"
printf "#ifndef %s\n" "$guard" >> "$OUTPUTH"
printf "#define %s\n" "$guard" >> "$OUTPUTH"
generate "$1" "$2" "$3" "$4"
echo "#endif" >> "$OUTPUTH"
exit 0