utils.lisp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. (defparameter *max-raw-bytes-print-len* 10 "Max number of octets to print from an array")
  12. (defun printable-array (array)
  13. "Given an array, return a string of the first *MAX-RAW-BYTES-PRINT-LEN* bytes"
  14. (let* ((len (length array))
  15. (print-len (min len *max-raw-bytes-print-len*))
  16. (printable-array (make-array print-len :displaced-to array)))
  17. (format nil "[~:d of ~:d bytes] <~x>" print-len len printable-array)))
  18. (defun upto-null (string)
  19. "Trim STRING to end at first NULL found"
  20. (subseq string 0 (position #\Null string)))
  21. (defun dump-data (file-name data)
  22. (with-open-file (f file-name :direction :output :if-exists :supersede :element-type '(unsigned-byte 8))
  23. (write-sequence data f)))
  24. (defmethod has-extension ((n string) ext)
  25. "Probably should use CL's PATHNAME methods, but simply looking at the .XXX portion of a filename
  26. to see if it matches. This is the string version that makes a PATHNAME and calls the PATHNAME version."
  27. (has-extension (parse-namestring n) ext))
  28. (defmethod has-extension ((p pathname) ext)
  29. "Probably should use CL's PATHNAME methods , but simply looking at the .XXX portion of a filename
  30. to see if it matches. PATHNAME version."
  31. (let ((e (pathname-type p)))
  32. (if e
  33. (string= (string-downcase e) (string-downcase ext))
  34. nil)))