forked from stassats/lisp-bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcocoa-lookup.lisp
40 lines (33 loc) · 1.37 KB
/
cocoa-lookup.lisp
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
(defpackage :cocoa-lookup (:use :common-lisp)
(:export :populate-table :symbol-lookup))
(in-package :cocoa-lookup)
(defparameter *appkit-root* "http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/")
(defparameter *foundation-root* "http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/")
(defparameter *appkit-file*
(merge-pathnames "appkit.lisp-expr"
(or #.*compile-file-truename* *default-pathname-defaults*)))
(defparameter *foundation-file*
(merge-pathnames "foundation.lisp-expr"
(or #.*compile-file-truename* *default-pathname-defaults*)))
(defvar *table* nil)
(defvar *populated-p* nil)
(defun populate-table ()
(unless *populated-p*
(with-open-file (r *appkit-file* :direction :input)
(setf *table* (make-hash-table :test #'equalp))
(let ((s (read r)))
(loop for i in s do (setf (gethash (car i) *table*)
(concatenate 'string *appkit-root* (cdr i))))))
(with-open-file (r *foundation-file* :direction :input)
(let ((s (read r)))
(loop for i in s do (setf (gethash (car i) *table*)
(concatenate 'string *foundation-root* (cdr i))))))
'done)
(setf *populated-p* t))
(defun symbol-lookup (symbol)
(unless *populated-p*
(populate-table))
(multiple-value-bind (val found)
(gethash symbol *table*)
(if found
val)))