Last active
September 15, 2020 11:04
-
-
Save slmjkdbtl/9f46654e2192c477bb2bd8ae68773124 to your computer and use it in GitHub Desktop.
cres.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
help() { | |
echo "Recursively convert resource files into embeddable C headers" | |
echo "" | |
echo "USAGE" | |
echo " $ cres <src> <dest>" | |
} | |
if [ -z "$1" ] || [ -z "$2" ] | |
then | |
help | |
exit 1 | |
fi | |
if [ ! -d "$1" ] | |
then | |
echo "$1 not found" | |
exit 1 | |
fi | |
base_path=$(pwd) | |
src_path="$1" | |
dest_path="$2" | |
mkdir -p "$dest_path" | |
convert() { | |
for entry in "$1"/* | |
do | |
dest=$dest_path${entry##$src_path} | |
if [ -d "$entry" ] | |
then | |
mkdir -p "$dest" | |
convert "$entry" | |
else | |
echo "$entry -> $dest.h" | |
cd "$1" || exit | |
xxd -i "${entry##$1/}" > "$base_path/$dest.h" | |
cd "$base_path" || exit | |
fi | |
done | |
} | |
convert "$src_path" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment