utils.lisp 1.3 KB

123456789101112131415161718192021222324252627282930
  1. ;;; -*- Mode: Lisp; show-trailing-whitespace: t; Base: 10; indent-tabs: nil; Syntax: ANSI-Common-Lisp; Package: UTILS; -*-
  2. ;;; Copyright (c) 2013, Mark VandenBrink. All rights reserved.
  3. (in-package #:utils)
  4. (defun warn-user (format-string &rest args)
  5. "print a warning error to *ERROR-OUTPUT* and continue"
  6. ;; COMPLETELY UNPORTABLE!!!
  7. (format *error-output* "~&****************************************~%")
  8. (format *error-output* "~&~&WARNING in ~a:: " (ccl::%last-fn-on-stack 1))
  9. (apply #'format *error-output* format-string args)
  10. (format *error-output* "~%~%")
  11. (format *error-output* "****************************************~%"))
  12. (defparameter *max-raw-bytes-print-len* 10 "Max number of octets to print from an array")
  13. (defun printable-array (array)
  14. "Given an array, return a string of the first *MAX-RAW-BYTES-PRINT-LEN* bytes"
  15. (let* ((len (length array))
  16. (print-len (min len *max-raw-bytes-print-len*))
  17. (printable-array (make-array print-len :displaced-to array)))
  18. (format nil "[~:d of ~:d bytes] <~x>" print-len len printable-array)))
  19. (defun upto-null (string)
  20. "Trim STRING to end at first NULL found"
  21. (subseq string 0 (position #\Null string)))
  22. (defun dump-data (file-name data)
  23. (with-open-file (f file-name :direction :output :if-exists :supersede :element-type '(unsigned-byte 8))
  24. (write-sequence data f)))