;;; -*- Mode:LISP; Package:USER; Readtable:CL; Base:10 -*-

(defvar *mark-file-property* :dont-delete)
(defvar *mark-file-valid-properties*  '(:dont-delete :dont-reap :author :not-backed-up))

(defun mark-files(directory name &optional host type version)
  (assert (si:parse-host host t) (host) "~a is not a known host." host)
  (unless (member *mark-file-property* *mark-file-valid-properties*)
    (cerror "Proceed anyway (it's your funeral) to set ~a property"
	    "~a is not a valid file property you can mark"
	    *mark-file-property*))
  (let* ((path (make-pathname :host host :directory directory
			      :name (or name :wild) :type (or type :wild)
			      :version (or version :highest)))
	 (files (directory path))
	 (set-to :init)
	 (property *mark-file-property*))
    (format t "~&Files for ~a are:~&  ~~{~s~}~" path files)
    (when (yes-or-no-p "Mark all for ~a?" property)
      (print
	(case (fquery '(:type :tyi :choices (((t "True") #\T)
					     ((nil "False") #\N)
					     ((:ask "Value") #\V)))
		      "How do you want it set?")
	  (NIL nil)
	  (:ask :ask)
	  (t t)))
      (dolist (file files)
	(send file :change-properties property
	      (let* ((plist (send file :properties))
		     (value (get plist property)))
		(cond
		  ((eq set-to :swap) (not value))
		  ((eq set-to t) t)
		  ((eq set-to nil) nil)
		  ((eq set-to :init)
		   (format t "File ~a has a value of ~s for property ~s."
			   file value property)))))))))
