This repository has been archived on 2022-05-21. You can view files and clone it, but cannot push or open issues or pull requests.
LEFTONE/tool/bin2c.sh
falsycat 80b3b82332 [RELEASE] u22-v04
This version is submitted for U22 final presentation. (squashed 158 commits)
2021-02-07 00:00:00 +00:00

20 lines
365 B
Bash
Executable File

#!/bin/bash
set -eu
if [[ -z ${1+x} || -z ${2+x} ]]; then
echo "usage: cat <file> | ./bin2c.sh <identifier name> <output name>"
exit 1
fi
name=$(sed -e 's/[^A-z0-9_]/_/g' <<< "$1")
hpath="$2.h"
cpath="$2.c"
data=$(cat - | xxd -i)
size=$(wc -w <<< "$data")
echo "const char $name[$size] = {$data};" > $cpath
echo "extern const char $name[$size];" > $hpath