DELETED multi-glob.scm Index: multi-glob.scm ================================================================== --- multi-glob.scm +++ /dev/null @@ -1,40 +0,0 @@ -(define (multi-glob pathspec) - (let* ((path-parts (intersperse (string-split pathspec "/" #t) "/"))) - (if (null? path-parts) - '() - (let loop ((parts (cdr path-parts)) - (result (let ((p (car path-parts))) - (if (string=? p "") - '("/") - (glob (car path-parts)))))) - (if (null? parts) - result - (let* ((part (car parts)) - (rem (cdr parts))) - (loop rem - (apply append - (map (lambda (curr) - (let ((new (string-append curr part))) - (cond - ((and (directory? curr)(file-read-access? curr)) - (glob new)) - ((member part '("." ".." "/")) new) - (else '())))) - result))))))))) - -;; alternative implementation - -(define (path-glob pattern) - (let ((parts (string-split pattern "/" '()))) - (if (null? parts) - '() - (glob-expand (car parts) (cdr parts)) - ))) - -(define (glob-expand pattern #!optional (rest '())) - (let ((result '()) (expanded (glob pattern))) - (apply append result (cond - ((null? expanded) (list '())) - ((null? rest) (list expanded)) - (else (map (lambda (x) (if (directory? x) (glob-expand (conc x "/" (car rest)) (cdr rest)) '())) expanded)) - )))) ADDED path-glob/path-glob.scm Index: path-glob/path-glob.scm ================================================================== --- /dev/null +++ path-glob/path-glob.scm @@ -0,0 +1,40 @@ +(define (multi-glob pathspec) + (let* ((path-parts (intersperse (string-split pathspec "/" #t) "/"))) + (if (null? path-parts) + '() + (let loop ((parts (cdr path-parts)) + (result (let ((p (car path-parts))) + (if (string=? p "") + '("/") + (glob (car path-parts)))))) + (if (null? parts) + result + (let* ((part (car parts)) + (rem (cdr parts))) + (loop rem + (apply append + (map (lambda (curr) + (let ((new (string-append curr part))) + (cond + ((and (directory? curr)(file-read-access? curr)) + (glob new)) + ((member part '("." ".." "/")) new) + (else '())))) + result))))))))) + +;; alternative implementation + +(define (path-glob pattern) + (let ((parts (string-split pattern "/" '()))) + (if (null? parts) + '() + (glob-expand (car parts) (cdr parts)) + ))) + +(define (glob-expand pattern #!optional (rest '())) + (let ((result '()) (expanded (glob pattern))) + (apply append result (cond + ((null? expanded) (list '())) + ((null? rest) (list expanded)) + (else (map (lambda (x) (if (directory? x) (glob-expand (conc x "/" (car rest)) (cdr rest)) '())) expanded)) + )))) ADDED path-glob/test.scm Index: path-glob/test.scm ================================================================== --- /dev/null +++ path-glob/test.scm @@ -0,0 +1,44 @@ +(use test posix srfi-1) +(load "path-glob.scm") + +(define globbers `((multi-glob . ,multi-glob)(path-glob . ,path-glob))) +(define interesting-patts '("../*/*" "/*/bin/*" "./*/bin/*")) +(define simple-patts '("../*" "/*" "/bin/*" "." ".." "*")) + +(define (trim-list lst) + (if (> (length lst) 3) + (append (take lst 3) '(...)) + lst)) + +(define (generate-prefix patt) + (write (conc "patt: " patt (make-string (- 10 (string-length patt)) #\ )))) + +(print "\nCompare each globber with glob") ;; can only do one level globs here +(for-each + (lambda (globber) + (print "\n\nGlobber: " globber) + (for-each + (lambda (patt) + (generate-prefix patt) + (test #f '() (trim-list + (lset-xor string=? ((alist-ref globber globbers) patt)(glob patt))))) + simple-patts)) + (map car globbers)) + +(print "\nTest the globbers against patts - only checks for resiliance, not correctness.") +(for-each + (lambda (patt) + (generate-prefix patt)(test #f #t (list? (path-glob patt))) + (generate-prefix patt)(test #f #t (list? (multi-glob patt))) + ) + interesting-patts) + +(print "Compare the globbers") +(for-each + (lambda (patt) + (generate-prefix patt) + (test #f '() (trim-list + (lset-xor string=? (path-glob patt)(multi-glob patt))))) + interesting-patts) + +(test-exit)