diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-05-09 00:39:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-09 00:39:17 +0200 |
commit | 0e873a30f3072dbacfb700f1e331a8c8396f2e1f (patch) | |
tree | 557792d454fef510a90975bed4e7d1650ee26c4f /scripts/gencharblob.lua | |
parent | a9981e0e7e9439340bb8c0162f860b78d8002559 (diff) | |
parent | 5b6d598ca8301682d931539ecd6da6a9fabae569 (diff) | |
download | rneovim-0e873a30f3072dbacfb700f1e331a8c8396f2e1f.tar.gz rneovim-0e873a30f3072dbacfb700f1e331a8c8396f2e1f.tar.bz2 rneovim-0e873a30f3072dbacfb700f1e331a8c8396f2e1f.zip |
Merge #4411 from ZyX-I/luaviml'/lua
Diffstat (limited to 'scripts/gencharblob.lua')
-rw-r--r-- | scripts/gencharblob.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/gencharblob.lua b/scripts/gencharblob.lua new file mode 100644 index 0000000000..d860375e26 --- /dev/null +++ b/scripts/gencharblob.lua @@ -0,0 +1,48 @@ +if arg[1] == '--help' then + print('Usage:') + print(' gencharblob.lua source target varname') + print('') + print('Generates C file with big uint8_t blob.') + print('Blob will be stored in a static const array named varname.') + os.exit() +end + +assert(#arg == 3) + +local source_file = arg[1] +local target_file = arg[2] +local varname = arg[3] + +source = io.open(source_file, 'r') +target = io.open(target_file, 'w') + +target:write('#include <stdint.h>\n\n') +target:write(('static const uint8_t %s[] = {\n'):format(varname)) + +num_bytes = 0 +MAX_NUM_BYTES = 15 -- 78 / 5: maximum number of bytes on one line +target:write(' ') + +increase_num_bytes = function() + num_bytes = num_bytes + 1 + if num_bytes == MAX_NUM_BYTES then + num_bytes = 0 + target:write('\n ') + end +end + +for line in source:lines() do + for i = 1,string.len(line) do + byte = string.byte(line, i) + assert(byte ~= 0) + target:write(string.format(' %3u,', byte)) + increase_num_bytes() + end + target:write(string.format(' %3u,', string.byte('\n', 1))) + increase_num_bytes() +end + +target:write(' 0};\n') + +source:close() +target:close() |