Megatest

Diff
Login

Differences From Artifact [3de22bebd8]:

To Artifact [80dc7776c7]:


1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38


39
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))
      ))))



>





|









>



|













>
|
|
|
|
>
>
|
|
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(define (multi-glob pathspec)
  (let* ((path-parts (intersperse (string-split pathspec "/" #t) "/")))
    (print "path-parts: " path-parts)
    (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)))
				      (print "new: " new " part: " part)
				      (cond
				       ((and (directory? curr)(file-read-access? curr))
					(glob new))
				       ((member part '("." ".." "/")) (list new part))
				       (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))))))