Cleaned up the CONSTANT-GLOB? function a bit.

This commit is contained in:
shivers 1997-10-06 21:14:20 +00:00
parent ff5d65fc30
commit 38c76cdf84
1 changed files with 10 additions and 14 deletions

View File

@ -129,21 +129,17 @@
;;; Is the glob pattern free of *'s, ?'s and [...]'s?
(define (constant-glob? pattern)
(let ((patlen (string-length pattern)))
(let lp ((i 0)
(escape? #f)) ; Was last char an escape char (backslash)?
(if (= i patlen)
(if escape?
(error "Ill-formed glob pattern" pattern)
#t)
(let lp ((i 0))
(or (= i patlen)
(let ((next-i (+ i 1)))
(if escape? (lp next-i #f)
(case (string-ref pattern i)
((#\\) ; Escape char
(if (= next-i patlen)
(error "Ill-formed glob pattern -- ends in backslash"
pattern)
(lp (+ next-i 1))))
((#\* #\? #\[) #f)
((#\\) (lp next-i #t))
(else (lp next-i #f)))
(lp next-i #f)))))))
(else (lp next-i))))))))
;;; Make an effort to get the files in the putative directory PATH.