diff options
author | 2015-01-10 13:30:30 +0100 | |
---|---|---|
committer | 2015-01-10 13:30:30 +0100 | |
commit | 8556d0cdf7058be2c519bd4d8e7006ea9e913527 (patch) | |
tree | 09594058dc17564b4ff3c106581d0856cf69c2d5 /3rdparty/mongoose/scripts/embed_binary_files.pl | |
parent | 61f7cd05dfed932dd1be927608a4989c187cc737 (diff) |
Added integral source of mongoose (nw)
Diffstat (limited to '3rdparty/mongoose/scripts/embed_binary_files.pl')
-rw-r--r-- | 3rdparty/mongoose/scripts/embed_binary_files.pl | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/3rdparty/mongoose/scripts/embed_binary_files.pl b/3rdparty/mongoose/scripts/embed_binary_files.pl new file mode 100644 index 00000000000..cf75a0d254c --- /dev/null +++ b/3rdparty/mongoose/scripts/embed_binary_files.pl @@ -0,0 +1,53 @@ +# This program is used to embed arbitrary data into a C binary. It takes +# a list of files as an input, and produces a .c data file that contains +# contents of all these files as collection of char arrays. +# +# Usage: perl <this_file> <file1> [file2, ...] > embedded_data.c + +foreach my $i (0 .. $#ARGV) { + open FD, '<:raw', $ARGV[$i] or die "Cannot open $ARGV[$i]: $!\n"; + printf("static const unsigned char v%d[] = {", $i); + my $byte; + my $j = 0; + while (read(FD, $byte, 1)) { + if (($j % 12) == 0) { + print "\n"; + } + printf ' %#04x,', ord($byte); + $j++; + } + print " 0x00\n};\n"; + close FD; +} + +print <<EOS; + +#include <stddef.h> +#include <string.h> + +static const struct embedded_file { + const char *name; + const unsigned char *data; + size_t size; +} embedded_files[] = { +EOS + +foreach my $i (0 .. $#ARGV) { + print " {\"$ARGV[$i]\", v$i, sizeof(v$i) - 1},\n"; +} + +print <<EOS; + {NULL, NULL, 0} +}; + +const char *find_embedded_file(const char *name, size_t *size) { + const struct embedded_file *p; + for (p = embedded_files; p->name != NULL; p++) { + if (!strcmp(p->name, name)) { + if (size != NULL) { *size = p->size; } + return (const char *) p->data; + } + } + return NULL; +} +EOS |