Austin Schuh | 24adb6b | 2015-09-06 17:37:40 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os, os.path, sys |
| 4 | |
| 5 | print """ |
| 6 | #include "internal/Embedded.h" |
| 7 | |
| 8 | #include <string> |
| 9 | #include <unordered_map> |
| 10 | |
| 11 | namespace { |
| 12 | |
| 13 | std::unordered_map<std::string, EmbeddedContent> embedded = { |
| 14 | """ |
| 15 | |
| 16 | for f in sys.argv[1:]: |
| 17 | bytes = open(f, 'rb').read() |
| 18 | print '{"/%s", {' % os.path.basename(f) |
| 19 | print '"' + "".join(['\\x%02x' % ord(x) for x in bytes]) + '"' |
| 20 | print ',%d }},' % len(bytes) |
| 21 | |
| 22 | print """ |
| 23 | }; |
| 24 | |
| 25 | } // namespace |
| 26 | |
| 27 | const EmbeddedContent* findEmbeddedContent(const std::string& name) { |
| 28 | auto found = embedded.find(name); |
| 29 | if (found == embedded.end()) { |
| 30 | return NULL; |
| 31 | } |
| 32 | return &found->second; |
| 33 | } |
| 34 | """ |
| 35 | |