application/octet-stream
•
1.23 KB
•
33 lines
#!/usr/bin/env nujel
[defn get-hex-cache []
[def ret [array/allocate 256]]
[dotimes [i 256 ret]
[array/set! ret i [fmt "0x{i:02X}, "]]]]
[defn create-c-asset [filename output-file symbol-name]
[typecheck/only filename :string]
[typecheck/only output-file :string]
[typecheck/only symbol-name :string]
[def raw [slurp filename]]
[def out [make-output-port [file/open-output* output-file :replace]]]
[out 'block-write "/* This file is auto-generated, manual changes will be overwritten! */\n"]
[out 'block-write [fmt "unsigned char {symbol-name}[] = "]]
[out 'block-write "{"]
[def hex-cache [get-hex-cache]]
[dotimes [i [buffer/length raw]]
[when [zero? [rem i 32]]
[out 'block-write "\n"]]
[out 'block-write [array/ref hex-cache [buffer/ref raw i]]]]
[out 'block-write "0\n};\n"]
[out 'close!]]
[defn main [args]
:export
[def filename [car args]]
[def output-file [cadr args]]
[def symbol-name [caddr args]]
[typecheck/only filename :string]
[typecheck/only output-file :string]
[typecheck/only symbol-name :string]
[create-c-asset filename output-file symbol-name]]