LuPPC/scripts/txt2c

56 lines
1.2 KiB
Plaintext
Raw Permalink 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() {
2016-01-14 11:10:04 +11:00
local LUAFILES="$1/*"
local OUTPUTH="$2"
local OUTPUTC="$3"
local PREFIX="$4"
2016-01-05 04:20:40 +11:00
2016-01-14 11:10:04 +11:00
local outname="$(basename "$OUTPUTH")"
2016-01-05 04:20:40 +11:00
outname="${outname%.*}"
2016-01-14 11:10:04 +11:00
local guard=$(echo "$outname" | tr '[:lower:]' '[:upper:]')
2016-01-05 04:20:40 +11:00
guard="$guard""_H"
for file in $LUAFILES
do
filename="$(basename "$file")"
if [ -d "$file" ]
then
2016-02-27 23:36:34 +11:00
echo "Enter directory $file"
2016-01-05 04:20:40 +11:00
generate $file $2 $3 ${PREFIX}${filename}_
else
filename="${filename%.*}"
2016-02-27 23:36:34 +11:00
echo "Generate $PREFIX$filename"
2016-01-05 04:20:40 +11:00
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