Removed makefile
[trivial-gtk.git] / gir-loader.lisp
blob411756c2895d1c1d47ce98fc7e9696d684c44e82
1 ;; Copyright (c) 2008 John Connors (johnc@yagc.ndo.remove.this.please.co.uk).
2 ;;
3 ;; Permission is hereby granted, free of charge, to any person obtaining a
4 ;; copy of this software and associated documentation files (the "Software"), to
5 ;; deal in the Software without restriction, including without limitation the
6 ;; rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 ;; sell copies of the Software, and to permit persons to whom the Software is
8 ;; furnished to do so, subject to the following conditions:
9 ;;
10 ;; The above copyright notice and this permission notice shall be included in all
11 ;; copies or substantial portions of the Software.
13 ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 ;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 ;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 ;; SOFTWARE.
21 (in-package :gir)
23 (defun lispize (fn-name)
24 "Turn a c-gtk name into a lisp one"
25 (intern (substitute #\- #\_
26 (if (symbolp fn-name)
27 (string fn-name)
28 fn-name))))
30 (defparameter *type-resolver-table* (make-hash-table :test 'equal))
32 (defun add-type (newtype basetype)
33 (setf (gethash newtype *type-resolver-table*) basetype))
35 (defun is-pointer (type)
36 (let ((type-string (string type)))
37 (char= (char type-string (1- (length type-string))) #\*)))
39 (defun dump-resolver-table ()
40 (iterate
41 (for (key val) in-hashtable *type-resolver-table*)
42 (format t "Type ~A~TResolution ~A~%" key val)))
44 (defun is-func-pointer (type)
45 (let* ((type-string (string type))
46 (type-string-len (length type-string)))
47 (or
48 (and (> type-string-len 4)
49 (string= "FUNC" (string-upcase (subseq type-string (- type-string-len 4)))))
50 (and (> type-string-len (length "Function"))
51 (string= "FUNCTION" (string-upcase (subseq type-string (- type-string-len (length "Function")))))))))
53 (defun resolve-type (type)
54 (cond
55 ((null type) :void)
56 ((is-pointer type) :pointer)
57 ((is-func-pointer type) :pointer)
59 (let ((result (gethash type *type-resolver-table* nil)))
60 (if (or (null result) (symbolp result))
61 (if result
62 (alexandria:make-keyword (string-upcase result))
63 (intern type))
64 (resolve-type result))))))
66 ;; instead of this, why not use defctype?
68 (add-type "gchar" :char)
69 (add-type "gint8" :int8)
70 (add-type "guint8" :uint8)
71 (add-type "gshort" :short)
72 (add-type "gint16" :int16)
73 (add-type "guint16" :uint16)
74 (add-type "glong" :long)
75 (add-type "gint" :int)
76 (add-type "int" :int)
77 (add-type "guint32" :uint32)
78 (add-type "gint32" :int32)
79 (add-type "gboolean" :int)
80 (add-type "guchar" :unsigned-char)
81 (add-type "gushort" :unsigned-short)
82 (add-type "gulong" :unsigned-long)
83 (add-type "guint" :unsigned-int)
84 (add-type "gfloat" :float)
85 (add-type "float" :float)
86 (add-type "gdouble" :double)
87 (add-type "double" :double)
88 (add-type "gpointer" :pointer)
89 (add-type "none" :void)
90 (add-type "void" :void)
91 (add-type "GType" :uint32) ;; might be a problem on 64-bit platforms
92 (add-type "GQuark" :uint32)
93 (add-type "GdkAtom" :pointer)
94 (add-type "Atom" :pointer)
96 (defun parse-gir (gir-in)
97 (s-xml:parse-xml gir-in :output-type :xml-struct))
99 (defun parse-gir-file (pathname)
100 (with-open-file (gir-in pathname)
101 (parse-gir gir-in)))
103 (defparameter *repository-names* '("cairo.gir"
104 "pango-1.0.gir"
105 "atk-1.0.gir"
106 "gtk-x11-2.0.gir"))
109 (defparameter *gir-files* nil)
111 (mapcar
112 (lambda (gir-name)
113 (push (parse-gir-file (cl-fad::pathname-as-file (concatenate 'string "gir-repository/gir/" gir-name)))) *gir-files*))