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

;;;FILE-MATCHER.LISP

;;;FILE-MATCHER makes a closure that will be a function acceptable to
k;$; aPe%fntoPs#a  iPemth^rP T#i u$ciPnwl $e h% sProPetp u$ciPn(.P.uRSO]EyFuLYS# pc)f nPeo)l "o a0hsHsH0
k;$;h$  aPe%fntoX ^eg ETuRv-|IEP) seiPyoc nPyfPrec]plvPldr$c"oPyecutrPdw$ehPrtPeflR mthRs n# hu0d
k;$; o-&ee "iet)r n%o$n"ee' ht"e$ h iPe"$ac#eP"aPds%ol  rc#se0.    t'Ht'Ht'Ht'Ht'Ht'Ht'Ht'Ht'Ht'HtFt'Ht'H0
k;;Pe"po#es^d0        
;;;
;;;FILE-MATCHER options provide control over the default answer per
k;;"iet)rX w$ehPr$iR mthRs\)$ h! u)r$ ie$u Pnscn\s nr#o$iPylv^ltqHtqHtqHtqHtqHtqHtqHtqHtqHtqHtFtqHtqHtqH0
k;&;"ebs)t &ee0.         

(defvar *file-match-list* nil
P |"#iPto iPemthPsecutrRd0) `&tL(t"L(0 6 0 6 0 6 0 6 0 6 0 
(defvar *file-match-default* nil
P t"e%a$l #nwPro$ ie$uY"0     `&t/L(t2L(0 6 0 6 0
(defvar *file-match-timeout* (* 10 60.)
P "ie$u PnscnRsY)0        `&tB0
(defvar *file-match-verbose* nil
P y"Pfn]nyN\L& "ebs #esgPs"aPe"pitRd0)   `&tL(tL(0 6 0 6 0 6 0 6 0 6 0 6 0 


  (let* ((file (first flist))
	 (dir (pathname-directory file))
	 (top (string (if (atom dir) dir (first dir)))))
    (if
      (rest
	(or (find top *file-match-list*
		  :key #'first
		  :test #'string-equal)
	    (first
	      (push (cons top
			  (y-or-n-p-with-timeout (* *file-match-timeout* 60.)
						 *file-match-default*
						 "Process ~a directory?" top))
		    *file-match-list*))))
      file
      ;;else
      (if *file-match-verbose*
	  (format t "~&Skipping ~a" file)))))

(eu i]emthXr&)einPl(e%a$lZ dr$c"o0
9	P  (e%a$lZ fl-$ac-e%a$lY*fuZt0)    `&rgL(rkL(0 6 0 6 0
9	P  $(ie$uZ fl-$ac$-ie$uY*m%oZtY)0    `&rL(rL(0 6 0 6 0
9	P  &("ebsZ fl-$ac&-"ebsY*)#oZeY))0   `&r&L(r)L(0 6 0 6 0 
  (let((*file-match-list* nil)
       (*file-match-default* default)
       (*file-match-timeout* timeout)
P   X *i]emt]hvr#oZe& "ebsY)0 `&tGL(tIL(0 6 0 6 0 6 0 6 0 6 0 6 0
    (closure '(*file-match-list*
	       *file-match-default*
	       *file-match-timeout*
P	   *i]emt]hvr#oZe")bsY*0  `&rgL(rjL(0 6 0 
	     'file-matcher2)))

,#0 

(defun test()
  (let((fcn (file-matcher))
       (fls '("joe;a" "joe;b" "joe;c"
	      "keith;foo" "keith;stuff" "keith;more"
	      "zozz;zozzle" "zozz.zizz;zozzle")))
    (dolist (file fls)
      (setq file (fs:parse-pathname file si:local-host))
      (format t "~%File ~s - ~:[skip it~;process it~]"
	      file
	      (funcall fcn (ncons file))))))

|#

