This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

find.scm



I was bored last night, looked at Jim's task list and decided that I would
give a find implementation in guile a shot. What I have so far is far from
complete, but still useful for simple tasks. 

You can get it from http://www.cs.purdue.edu/~lutterdc/software/find.scm

I'd appreciate any comments, suggestions etc. I include the start of
find.scm, i.e. the documentation :)

David

;; find -- a scheme implementation of the Unix favorite
;; (C) Copyright 1999 David Lutterkort <lutter@cise.ufl.edu>
;; This file is under the GNU General Public License, yadi yadi yada

;; Use:
;; (find dir pred [action])
;; Recurse through the directory tree DIR. For each file in this tree,
;; execute PRED. If PRED is true for a file F, (action F S) is called
;; where S is the result of (lstat F) to avoid repeated stats on the same
;; file. ACTION defaults to (lambda (f s) f)
;; 
;; FIND returns a list of all the results of the (action F S) calls.
;;
;; The PRED form must follow the following syntax:
;; PRED ::= (and PRED+) | (or PRED+) | (not PRED) | SIMPLE-PRED
;; 
;; A SIMPLE-PRED can be any of the following:
;;  a string T : filenames are matched against T, which is assumed
;;               to be a regexp (shell wildcards will come later)
;;  a procedure P : P should take zero, one or two arguments. P is called
;;                  for each file that find encounters. If it takes
;;                  arguments, the first argument passed is the filename
;;                  and the second argument (if P takes two args) is the
;;                  result of (lstat F)
;;
;; The boolean operators AND, OR and NOT are applied to the results of the
;; SIMPLE-PREDS resp. subforms of the PRED expression. The usual
;; short-circuiting of AND and OR is performed.
;;
;; There are a few predefined predicates at the end of the file.
;;
;; Examples:
;; (1) Find all EMACS backup files and record there names and size
;;     (find "somedir" ".*~$" (lambda (f s) (list f (stat:size s))))
;;
;; (2) EMACS backups bigger than 3k
;;     (find "somedir" (and ".*$" (size > 3 k)))
;;
;; (3) Empty texput.log files and dvi files bigger than 3M
;;     (find "somedir" (or (and "texput\\.log" empty)     
;;                         (and ".*dvi$" (size > 3 M))))
;;
;; Todo:
;; Tons of stuff ... like regexp matching stinks right now ... use shell
;; wildcards and be more efficient ... include more stock predicates
;; ... support the ones that GNU find supports ... let the user follow
;; symlinks somehow (they are never followed right now) ... add pruning: if
;; a predicate returns 'prune do not descend into that directory

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]