This repository was archived by the owner on Sep 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.lisp
More file actions
57 lines (55 loc) · 1.96 KB
/
util.lisp
File metadata and controls
57 lines (55 loc) · 1.96 KB
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
47
48
49
50
51
52
53
54
55
56
57
(defun write-fixnum (i &optional (stream *standard-output*))
(declare (optimize (speed 3)))
(declare (type fixnum i)
(type stream stream))
(if (= i 0)
(write-char #\0 stream)
(let ((weight (let ((x 1))
(declare (type (integer 0 #.(truncate most-positive-fixnum 10)) x))
(loop
(when (>= x i)
(return x))
(locally
(declare (fixnum x))
(setq x (* x 10))))))
(j i))
(declare (fixnum j))
(loop
(when (= weight 0)
(return))
(multiple-value-bind (d ni)
(floor j weight)
(if (or (/= d 0)
(/= i j))
(write-char (digit-char d) stream))
(setq j ni
weight (truncate weight 10)))))))
(defun glob (string pattern)
(declare (optimize (speed 3)))
(declare (simple-string string pattern))
(labels ((helper (i j)
;;(declare (type (integer 0 8192) i j))
(declare (type fixnum i j))
(loop
(let ((c (if (< i (length string)) (elt string i) nil))
(p (if (< j (length pattern)) (elt pattern j) nil)))
;;(format t "~A ~A~%" c p)
(cond
((and c (or (eql c p) (eql p #\?)))
)
((eql c p)
(return-from glob t))
((null c)
(return-from helper nil))
((eql p #\*)
(if (< j (length pattern))
(loop :for k :from i :to (length string)
:do (helper k (1+ j)))
t))
(t
(return-from helper nil))))
(when (< i (length string))
(incf i))
(when (< j (length string))
(incf j)))))
(helper 0 0)))