git.fiddlerwoaroof.com
Browse code

chore: cleanup utils

Edward authored on 10/03/2021 07:55:40
Showing 5 changed files
1 1
similarity index 66%
2 2
rename from kr.asd
3 3
rename to fwoar-kr.asd
... ...
@@ -1,20 +1,14 @@
1 1
 (in-package :asdf-user)
2 2
 
3
-(asdf:defsystem :org.kr
4
-  :depends-on (:cl-fad)
3
+(asdf:defsystem :fwoar-kr
4
+  :depends-on (:uiop)
5 5
   :license "MIT-ish (also public domain, see LICENSE)"
6 6
   :author "CMU Garnet Team (plus various others, see LICENSE)"
7 7
   :description " GUI toolkit (c. 1990 look/feel)"
8 8
   :components ((:file "package")
9
-               (:module utils
10
-                :pathname "utils"
11
-                :components ((:file "general")
12
-                             (:file "global")))
13 9
                (:module kr
14 10
                 :pathname "kr"
15
-                :depends-on (utils)
16 11
                 :components ((:file "kr-macros")
17 12
                              (:file "kr-doc")
18 13
                              (:file "kr")
19 14
                              (:file "constraints" :depends-on (kr))))))
20
-
... ...
@@ -1,29 +1,5 @@
1 1
 (in-package :cl-user)
2 2
 
3
-(defpackage :fwoar.garnet-utils
4
-  (:use :common-lisp)
5
-  (:nicknames :fw.gu)
6
-  (:export *garnet-break-key*
7
-           2pi -2pi
8
-           add-to-list
9
-           black
10
-           directory-p
11
-           do2lists
12
-           dolist2
13
-           m
14
-           m1
15
-           pi/2
16
-           pi3/2
17
-           safe-functionp
18
-           short-pi
19
-           str
20
-           string+
21
-           till
22
-           until
23
-           verify-binding
24
-           white
25
-           while))
26
-
27 3
 (defpackage :fwoar.kr-debug
28 4
   (:use :common-lisp))
29 5
 
... ...
@@ -94,4 +70,3 @@
94 70
            g-formula-value
95 71
            s-formula-value
96 72
            self-old-value))
97
-
98 73
deleted file mode 100644
... ...
@@ -1,178 +0,0 @@
1
-;;; -*- Mode: LISP; Syntax: Common-Lisp; Package: GARNET-UTILS; Base: 10 -*-
2
-
3
-
4
-;; The Garnet User Interface Development Environment.
5
-;;
6
-;; This code was written as part of the Garnet project at Carnegie
7
-;; Mellon University, and has been placed in the public domain.
8
-;;
9
-;; by David S. Kosbie
10
-
11
-;; Host of Lisp utilities used by other Garnet code.
12
-
13
-(in-package :fwoar.garnet-utils)
14
-
15
-(defvar *debug-utils-mode* t)
16
-
17
-(defconstant pi/2 (/ pi 2))
18
-(defconstant pi3/2 (* 3 (/ pi 2)))
19
-(defconstant 2PI (* 2 PI))
20
-(defconstant -2PI (- (* 2 PI)))
21
-(defconstant short-PI (coerce PI 'short-float))
22
-
23
-(defmacro while (test &rest body)
24
-  "Loop while test is true. If already not true, don't loop at all."
25
-  `(do ()
26
-     ((not ,test))
27
-     ,@body))
28
-
29
-(defmacro till (test &body body)
30
-  "Loop until test is true. If already true, don't loop at all."
31
-  `(do ()
32
-       (,test)
33
-     ,@body))
34
-
35
-;; Original Garnet version (loops at least once).
36
-(defmacro until (test &body body)
37
-  "Loop until test is true. Loops at least once."
38
-  `(loop ,@body
39
-      (when ,test (return))))
40
-
41
-(defmacro do2lists ((var1 list1 var2 list2 &key either?) &rest body)
42
- (let ((list1var  (gensym))
43
-       (list2var  (gensym))
44
-       (done-test (if either? 'and 'or)))
45
-  `(let ((,list1var ,list1)
46
-         (,list2var ,list2)
47
-         ,var1 ,var2)
48
-      (while (,done-test ,list1var ,list2var)
49
-        (setq ,var1 (car ,list1var))
50
-        (setq ,var2 (car ,list2var))
51
-        (setq ,list1var (cdr ,list1var))
52
-        (setq ,list2var (cdr ,list2var))
53
-       ,@body))))
54
-
55
-(defmacro dolist2 ((var1 var2 list) &rest body)
56
-  (let ((listvar (gensym)))
57
-  `(let ((,listvar ,list) ,var1 ,var2)
58
-     (while ,listvar
59
-       (setq ,var1 (car ,listvar))
60
-       (setq ,var2 (cadr ,listvar))
61
-       (setq ,listvar (cddr ,listvar))
62
-       ,@body))))
63
-
64
-(defmacro m (s-expr)
65
-  `(pprint (macroexpand (quote ,s-expr))))
66
-
67
-(defmacro m1 (s-expr)
68
-  `(pprint (macroexpand-1 (quote ,s-expr))))
69
-
70
-(defmacro string+ (&rest args) `(concatenate 'string ,@args))
71
-
72
-(defun add-to-list (element list &optional where locator)
73
-  "Add-to-list legal invocations:
74
-     (add-to-list element list)
75
-     (add-to-list element list :head) (or :front)
76
-     (add-to-list element list :tail) (or :back)
77
-     (add-to-list element list :before other-element)
78
-     (add-to-list element list :after other-element)"
79
- (let  ((new-cons (list element))
80
-        result)
81
-   (if (null list)
82
-       (setq result new-cons)
83
-       (case where
84
-         ((:head :front NIL)
85
-          (setq result (cons element list)))
86
-         ((:before)
87
-          (if (eq (first list) locator)
88
-              (setq result (cons element list))
89
-              (do ((cons1 list (cdr cons1))
90
-                   (cons2 (cdr list) (cdr cons2)))
91
-                  ((null cons2))
92
-                (when (eq (first cons2) locator)
93
-                  (setf (cdr new-cons) cons2)
94
-                  (setf (cdr cons1) new-cons)
95
-                  (setq result list)
96
-                  (return)))))
97
-         ((:after)
98
-          (do ((cons1 list (cdr cons1))
99
-               (cons2 (cdr list) (cdr cons2)))
100
-              ((null cons1))
101
-            (when (eq (first cons1) locator)
102
-              (setf (cdr new-cons) cons2)
103
-              (setf (cdr cons1) new-cons)
104
-              (setq result list)
105
-              (return))))))
106
- (unless result
107
-   (setf (cdr (last list)) new-cons)
108
-   (setq result list))
109
- result))
110
-
111
-
112
-;; Verify-Binding implementation
113
-;;
114
-;; Keep --- a demo uses this
115
-(defun verify-binding (string)
116
-  "Takes a string and returns the symbol coercion of the string if the
117
-   symbol is bound.  Note: The suffix of the string is converted to
118
-   all uppercase characters before checking if it is bound in the
119
-   package."
120
-  (let ((result-1 (verify-binding-aux string 0)))
121
-    (if result-1
122
-        (let* ((colon-p (first result-1))
123
-               (prefix (second result-1))
124
-               (symbol-1 (values (read-from-string prefix)))
125
-               (index (third result-1)))
126
-          (if colon-p
127
-              ;; Then symbol-1 indicates a package name
128
-              (when (find-package symbol-1)
129
-                ;; Then symbol-1 is a valid package name
130
-                (let ((result-2 (verify-binding-aux string (+ 1 index))))
131
-                  (when result-2
132
-                    ;; Then suffix indicates a var in the package symbol-1
133
-                    (let* ((suffix (string-upcase (second result-2)))
134
-                           (access-internal-p (fourth result-2)))
135
-                      (multiple-value-call
136
-                          #'(lambda (symbol-2 access)
137
-                              (if symbol-2
138
-                                  (if (or (eq access :external)
139
-                                          access-internal-p)
140
-                                      ;; verify that symbol-2 is not a function
141
-                                      (when (boundp symbol-2)
142
-                                        (values (read-from-string string)))
143
-                                      )))
144
-                        (find-symbol suffix symbol-1))))))
145
-              ;; Then symbol indicates a var in the working package
146
-              (when (and (not (numberp symbol-1)) (boundp symbol-1)) symbol-1))))))
147
-
148
-(defun verify-binding-aux (string start)
149
-  "Split the string at the colon(s) to return either the package name
150
-   or the symbol name if called where the first character is a colon."
151
-  (let ((str-len (length string)))
152
-    (when (> str-len start)
153
-      ;; Skip second colon if there is a double colon between package and var
154
-      (let ((access-internal-p (when (and (char= (char string start) #\:)
155
-                                          (/= start 0))
156
-                                 (incf start))))
157
-        ;; Abort if a special character begins the string
158
-        (unless (or (char= (char string start) #\:)
159
-                    (char= (char string start) #\#))
160
-          ;; Return the part of the string up to but not including the colon
161
-          ;; and the index of the last character checked
162
-          ;; FMG --- Just use lisp utilities to do this stuff.
163
-          (let* ((colon (position #\: string :start start :test #'char=))
164
-                 (new-string (subseq string start colon)))
165
-            (list (not (null colon))
166
-                  new-string
167
-                  (or colon (1- str-len))
168
-                  access-internal-p)))))))
169
-
170
-(defun safe-functionp (fn)
171
-  (or (functionp fn)
172
-      (and (symbolp fn) (fboundp fn))))
173
-
174
-(defun directory-p (pathname)
175
-  (cl-fad:directory-exists-p pathname))
176
-
177
-(defmacro str (&rest rest)
178
-  `(concatenate 'string ,@rest))
179 0
deleted file mode 100644
... ...
@@ -1,6 +0,0 @@
1
-
2
-(in-package :fwoar.garnet-utils)
3
-
4
-(defvar black nil)
5
-(defvar white nil)
6
-(defvar *garnet-break-key* :F1)
7 0
deleted file mode 100644
... ...
@@ -1,56 +0,0 @@
1
-(in-package :COMMON-LISP-USER)
2
-
3
-(eval-when (:execute :load-toplevel :compile-toplevel)
4
-  (defvar REFRESH-INIT
5
-    (progn
6
-      (garnet-load "gadgets:text-buttons-loader")
7
-      (garnet-load "gadgets:radio-buttons-loader"))))
8
-
9
-(defvar SMALL-FONT (opal:get-standard-font NIL NIL :small))
10
-
11
-(when (boundp 'REFRESH-WIN) (opal:destroy REFRESH-WIN))
12
-
13
-(create-instance 'REFRESH-WIN inter:interactor-window
14
-  (:left 515) (:top 365) (:height 110) (:width 120)
15
-  (:title "Keys")
16
-  (:aggregate (create-instance 'REFRESH-TOP-AGG opal:aggregate)))
17
-
18
-(opal:update REFRESH-WIN)
19
-
20
-(create-instance 'REFRESH gg:text-button
21
-  (:left 10) (:top 10)
22
-  (:text-offset 2) (:gray-width 3) (:shadow-offset 5)
23
-  (:font SMALL-FONT)
24
-  (:string "Refresh")
25
-  (:final-feedback-p NIL)
26
-  (:selection-function #'(lambda (gadget value)
27
-                           (declare (ignore gadget value))
28
-                           (opal:update-all T))))
29
-
30
-(defun function-key-fn (gadget value)
31
-  (declare (ignore gadget value))
32
-  (setf inter::*leftdown-key* 105
33
-        inter::*middledown-key* 107
34
-        inter::*rightdown-key* 113))
35
-
36
-(defun arrow-key-fn (gadget value)
37
-  (declare (ignore gadget value))
38
-  (setf inter::*leftdown-key* 123
39
-        inter::*middledown-key* 124
40
-        inter::*rightdown-key* 125))
41
-
42
-(create-instance 'MOUSE-KEYS gg:radio-button-panel
43
-  (:left 10) (:top 40)
44
-  (:font SMALL-FONT)
45
-  (:text-offset 2) (:gray-width 3) (:shadow-offset 5)
46
-  (:button-diameter 20)
47
-  (:items `(("Function keys" Function-key-fn)
48
-            ("Arrow keys" Arrow-key-fn))))
49
-
50
-(g-value MOUSE-KEYS :value)
51
-(s-value MOUSE-KEYS :value "Function keys")
52
-
53
-(opal:add-components REFRESH-TOP-AGG REFRESH MOUSE-KEYS)
54
-(opal:update REFRESH-WIN)
55
-
56
-(opal:update REFRESH-WIN T)