upscheme/scheme-core/dump.scm

13 lines
406 B
Scheme

(define (dump-buffer-as-c-literal buf)
(princ "char boot_image[] = \"")
(let next ((i 0))
(let ((char (read-u8 buf)))
(if (not (io.eof? buf))
(let ((code (+ char 0)))
(if (= 0 (mod i 16)) (princ "\"\n\""))
(princ "\\x")
(if (< code #x10) (princ "0"))
(princ (number->string code 16))
(next (+ i 1))))))
(princ "\";\n"))