3 (define-foreign-library libsane
4 (:unix
(:or
"libsane.so.1" "libsane.so"))
5 (t (:default
"libsane")))
7 (defun sane-interpret-version (n)
8 "Read bitstring for version and output the correct major/minor/rev
12 (boole boole-and
(ash n -
16) 255) ; minor
13 (boole boole-and n
65535)))
15 (defmacro with-init
(version-sym &body body
)
16 "Run BODY with VERSION-SYM set to a triple representing the version of libsane
17 that is running. Evaluates to BODY. If VERSION-SYM is nil, there is no symbol
18 bound to the version."
19 (let ((c-version (gensym)))
22 (with-foreign-object (,c-version
:int
)
23 (use-foreign-library libsane
)
24 (sane-lowlevel:ensure-ok
25 (sane-lowlevel::sane_init
,c-version
(null-pointer))
26 "Failed to initialise sanelib.")
28 (let ,(when version-sym
29 `((,version-sym
(sane-interpret-version
30 (mem-ref ,c-version
:int
)))))
32 (sane-lowlevel::sane_exit
))))