upscheme/scheme-core/dump.scm

17 lines
716 B
Scheme

(define (dump-buffers-as-c-literal . bufs)
(display "char boot_image[] = \"")
(let loop-bufs ((bufs bufs))
(if (not (null? bufs))
(begin (let ((buf (car bufs)))
(let loop-buf-bytes ((i 0))
(let ((char (read-u8 buf)))
(if (not (io.eof? buf))
(let ((code (+ char 0)))
(if (= 0 (mod i 16)) (display "\"\n\""))
(display "\\x")
(if (< code #x10) (display "0"))
(display (number->string code 16))
(loop-buf-bytes (+ i 1)))))))
(loop-bufs (cdr bufs)))))
(display "\";\n"))