... |
... |
@@ -22,8 +22,7 @@ |
22
|
22
|
read-char-no-edit listen-skip-whitespace concat-pnames
|
23
|
23
|
iterate once-only collect do-anonymous undefined-value
|
24
|
24
|
required-argument define-hash-cache defun-cached
|
25
|
|
- cache-hash-eq do-hash
|
26
|
|
- with-temporary-file))
|
|
25
|
+ cache-hash-eq do-hash))
|
27
|
26
|
|
28
|
27
|
(import 'lisp::whitespace-char-p)
|
29
|
28
|
|
... |
... |
@@ -613,73 +612,3 @@ |
613
|
612
|
"Return an EQ hash of X. The value of this hash for any given object can (of
|
614
|
613
|
course) change at arbitary times."
|
615
|
614
|
`(lisp::pointer-hash ,x)) |
616
|
|
-
|
617
|
|
-;;; WITH-TEMPORARY-FILE -- Public
|
618
|
|
-(defmacro with-temporary-file ((var template-prefix
|
619
|
|
- &key
|
620
|
|
- (element-type 'base-char)
|
621
|
|
- (external-format :default)
|
622
|
|
- (buffering :full)
|
623
|
|
- decoding-error
|
624
|
|
- encoding-error)
|
625
|
|
- &parse-body (forms decls))
|
626
|
|
- _N"A temporary file is opened using the Open-args and bound to the
|
627
|
|
- variable Var. The name of the temporary file uses Template-prefix
|
628
|
|
- for the name. If the temporary file cannot be opened, the forms are
|
629
|
|
- not evaluated. The Forms are executed, and when they terminate,
|
630
|
|
- normally or otherwise, the file is closed.
|
631
|
|
-
|
632
|
|
- Defined keywords:
|
633
|
|
- :element-type - Type of object to read or write. Default BASE-CHAR
|
634
|
|
- :external-format - An external format name
|
635
|
|
- :buffering - Buffering to use for the file. Must be one of
|
636
|
|
- :NONE, :LINE, :FULL
|
637
|
|
- :decoding-error - How to handle decoding errors. See OPEN
|
638
|
|
- :encoding-error - How to handle encoding errors. See OPEN"
|
639
|
|
- (let ((abortp (gensym))
|
640
|
|
- (template (gensym "TEMPLATE-"))
|
641
|
|
- (fd (gensym "FD-")))
|
642
|
|
-
|
643
|
|
- `(let* ((,template (concatenate 'string
|
644
|
|
- ,template-prefix
|
645
|
|
- "XXXXXX"))
|
646
|
|
- (,fd (unix::unix-mkstemp ,template)))
|
647
|
|
- (unless ,fd
|
648
|
|
- (error "Could not create temporary file using template ~A"
|
649
|
|
- ,template))
|
650
|
|
- (let ((,var (lisp::make-fd-stream (unix::unix-mkstemp ,template)
|
651
|
|
- :auto-close t
|
652
|
|
- :file ,template
|
653
|
|
- :output t
|
654
|
|
- :input t
|
655
|
|
- :element-type ',element-type
|
656
|
|
- :external-format ,external-format
|
657
|
|
- :decoding-error ,decoding-error
|
658
|
|
- :encoding-error ,encoding-error
|
659
|
|
- :buffering ,buffering))
|
660
|
|
- (,abortp t))
|
661
|
|
- ,@decls
|
662
|
|
- (unwind-protect
|
663
|
|
- (multiple-value-prog1
|
664
|
|
- (progn ,@forms)
|
665
|
|
- (setq ,abortp nil))
|
666
|
|
- (when ,var
|
667
|
|
- (close ,var :abort ,abortp)))))))
|
668
|
|
-
|
669
|
|
-;; WITH-TEMPORARY-DIRECTORY -- Public
|
670
|
|
-(defmacro with-temporary-directory ((var template-prefix)
|
671
|
|
- &parse-body (forms decls))
|
672
|
|
- _N"Create a temporary directory using Template-prefix as the name of the directory."
|
673
|
|
- (let ((template (gensym "TEMPLATE-")))
|
674
|
|
- `(let ((,template (concatenate 'string ,template-prefix
|
675
|
|
- "XXXXXX")))
|
676
|
|
- ,@decls
|
677
|
|
- (let ((,var (unix::unix-mkdtemp ,template)))
|
678
|
|
- (unless ,var
|
679
|
|
- (error "Could not create temporary directory using template ~A"
|
680
|
|
- ,template))
|
681
|
|
- (unwind-protect
|
682
|
|
- (multiple-value-prog1
|
683
|
|
- (progn ,@forms)))
|
684
|
|
- ;; Remove the directory
|
685
|
|
- (unix:unix-rmdir ,var))))) |