LuPPC/scripts/txt2c
2016-01-03 03:25:12 +01:00

41 lines
792 B
Bash
Executable File

#!/bin/bash
# $1 scripts folder
# $2 file to generate OUTPUTH C
# $3 file to generate OUTPUTH H
# $4 prefix
LUAFILES="$1/*"
OUTPUTH="$2"
OUTPUTC="$3"
PREFIX="$4"
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"
for file in $LUAFILES
do
filename="$(basename "$file")"
filename="${filename%.*}"
echo "extern char $PREFIX$filename[];" >> "$OUTPUTH"
echo "char $PREFIX$filename[] = {" >> "$OUTPUTC"
echo " " $(xxd -i < "$file") ",0x00" >> "$OUTPUTC"
echo "};" >> "$OUTPUTC"
done
echo "#endif" >> "$OUTPUTH"
exit 0