forked from ct-Open-Source/Basecamp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata2header.sh
56 lines (45 loc) · 1.32 KB
/
data2header.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
echo "Converting files in folder \"data\" to C Header file data.h"
DATA="data/"
CURRDIR="$(pwd)"
TMPDIR="$CURRDIR/tmp/"
OUTFILE="$CURRDIR/data.hpp"
mkdir $TMPDIR
#change into data folder
cp $DATA/* $TMPDIR
cd $TMPDIR
yuicompressor -o '.css$:.css' *.css
yuicompressor -o '.js$:.js' *.js
# :a;N;$!ba; will move all lines into the pattern space (internal buffer of sed)
# so that the next command will also remove the line breaks (which are also whitespaces)
# s/>\s*</></g' will remove all whitespaces between the HTML tags
# example:
#">
# <" becomes "><"
sed -i ':a;N;$!ba;s/>\s*</></g' *.htm
gzip *
cat > $OUTFILE <<DELIMITER
/*
Basecamp - ESP32 library to simplify the basics of IoT projects
Written by Merlin Schumacher (mls@ct.de) for c't magazin für computer technik (https://www.ct.de)
Licensed under GPLv3. See LICENSE for details.
*/
#include <pgmspace.h>
//
// converted data/* to gzipped flash variables
//
DELIMITER
#convert contents into array of bytes
INDEX=0
for i in $(ls -1); do
CONTENT=$(cat $i | xxd -i)
CONTENT_LEN=$(echo $CONTENT | grep -o '0x' | wc -l)
FILENAME=${i//[.]/_}
printf "#define "$FILENAME"_len "$CONTENT_LEN"\n" >> $OUTFILE
printf "const uint8_t "$FILENAME"[] PROGMEM {\n$CONTENT\n};" >> $OUTFILE
echo >> $OUTFILE
unset CONTENT
done
rm $TMPDIR/*
rmdir $TMPDIR
cd $CURRDIR