(in-package :com.tee-it-up-golf.util)

(defmacro with-assoc ((&rest keys) assoc &body forms)
  (with-unique-names (alist)
    `(let ((,alist ,assoc))
       (let ,(mapcar (lambda (key) `(,key  (cdr (assoc ',key ,alist))))
		     keys)
	 ,@forms))))

(defun stream->bytes (stream)
  (let ((byte-buffer (make-array
		      (file-length stream)
		      :element-type 'unsigned-byte)))
    (read-sequence byte-buffer stream)
    byte-buffer))

(defun strip-time (time)
  (multiple-value-bind (second minute hour date month year)
      (decode-universal-time time)
    (declare (ignore second minute hour))
    (encode-universal-time 0 0 0 date month year)))

(defun brief-date (&optional (date (get-universal-time)))
  (multiple-value-bind (s m h date month year) (decode-universal-time date)
    (declare (ignore s m h))
    (format nil "~4D-~2D-~2D" year month date)))


(defun initialize-window (window)
  "Initialize window component for calling from a dispatcher"
  (setf (ucw-core::component.calling-component window) nil
	(ucw-core::component.place window) (ucw-core::make-place
					    (ucw-core:context.window-component
					     ucw-core:*context*))
	(ucw-core::parent window) nil
	(ucw-core::context.window-component ucw-core:*context*) window))