LuPPC/scripts/txt2c

53 lines
1.1 KiB
Plaintext
Raw Normal View History

2016-01-03 13:25:12 +11:00
#!/bin/bash
# $1 scripts folder
# $2 file to generate OUTPUTH C
# $3 file to generate OUTPUTH H
# $4 prefix
2016-01-05 04:20:40 +11:00
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
}
2016-01-03 13:25:12 +11:00
2016-01-05 04:20:40 +11:00
OUTPUTH="$2"
2016-01-03 13:25:12 +11:00
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"
2016-01-05 04:20:40 +11:00
generate "$1" "$2" "$3" "$4"
2016-01-03 13:25:12 +11:00
echo "#endif" >> "$OUTPUTH"
exit 0