dump.lisp 762 B

1234567891011121314151617181920212223242526272829
  1. (asdf:operate 'asdf:load-op 'hurd)
  2. (use-package 'hurd)
  3. ;;
  4. ;; This file tries to mimick in Lisp the dump.c program
  5. ;; from The Hurd Hacking Guide (http://www.gnu.org/software/hurd/hacking-guide/hhg.html)
  6. ;;
  7. (defun array->string (arr)
  8. (let ((ret (make-array 0
  9. :element-type 'character :fill-pointer 0
  10. :adjustable t)))
  11. (loop for item across arr
  12. unless (eq item 0)
  13. do (vector-push-extend (code-char item) ret))
  14. ret))
  15. (defun dump-file (path)
  16. (with-port-deallocate (file (file-name-lookup path '(:read)))
  17. (let ((data (io-read file)))
  18. (when data
  19. (array->string data)))))
  20. ;; to print results just like the C version, do:
  21. ;; (format t "~a" (dump-file "myfile"))