From: Vladimir Zolotykh
Subject: asdf:concatenate-op
Date: 
Message-ID: <dn9bk5$252$1@dcs.eurocom.od.ua>
Could you please improve the following code? It's my fible attempt to do
concatenation in ASDF. I don't like in it
that it opens destination file many times. I even don't see how it could
be possible to avoid opening dest. file many times if it were done in 
ASDF fashion.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass concatenate-op (operation)
   ((destination :initarg :destination
		:reader concatenate-op-destination
		:initform nil)
    (verbose :initarg :verbose :initform nil
	    :reader concatenate-op-verbose)))
(defmethod concatenate-op-default-destination ((op concatenate-op)
					       (c cl-source-file))
   (or (concatenate-op-destination op)
       (merge-pathnames
        (component-name (component-system c))
        (make-pathname :type (pathname-type
			     (car (input-files op c)))))))

(defmethod perform ((op concatenate-op) (c cl-source-file))
   (with-open-file (to (concatenate-op-default-destination op c)
		   :direction :output
		   :element-type 'unsigned-byte :if-exists :append
		   :if-does-not-exist :create)
     (with-open-file (from (car (input-files op c))
		     :element-type 'unsigned-byte)
       (when (concatenate-op-verbose op)
	(format *verbose-out* "~&;;; Appending ~A to ~A~%"
		(namestring from) (namestring to)))
       (loop for b = (read-byte from nil nil) while b
	  do (write-byte b to))))
   nil)
(defmethod explain ((op concatenate-op) (c cl-source-file))
   (format *verbose-out* "~&;;; Appending ~A to ~A~%"
	  (car (input-files op c))
	  (concatenate-op-default-destination op c)))

(defmethod component-depends-on ((operation concatenate-op)
				 (c component))
   (cons (list 'compile-op (component-name c))
         (call-next-method)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-- 
Vladimir Zolotykh