]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/libraries/finder/windows/windows.factor
factor: trim using lists
[factor.git] / basis / alien / libraries / finder / windows / windows.factor
1 ! Copyright (C) 2013 Björn Lindqvist, John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: alien.c-types alien.data alien.libraries.finder
5 alien.strings arrays combinators.short-circuit environment
6 io.backend io.files io.files.info io.pathnames kernel sequences
7 specialized-arrays splitting system system-info.windows
8 windows.kernel32 ;
9 FROM: alien.c-types => ushort ;
10 SPECIALIZED-ARRAY: ushort
11 IN: alien.libraries.finder.windows
12
13 <PRIVATE
14
15 : search-paths ( -- seq )
16     "resource:" normalize-path
17     system-directory
18     windows-directory 3array
19     "PATH" os-env [ ";" split ] [ f ] if* append ;
20
21 : candidate-paths ( name -- seq )
22     search-paths over ".dll" tail? [
23         [ prepend-path ] with map
24     ] [
25         [
26             [ prepend-path ]
27             [ [ ".dll" append ] [ prepend-path ] bi* ] 2bi
28             2array
29         ] with map concat
30     ] if ;
31
32 : find-library-paths ( name -- path/f )
33     candidate-paths [
34         { [ file-exists? ] [ file-info regular-file? ] } 1&&
35     ] find nip ;
36
37 : find-library-file ( name -- path/f )
38     f DONT_RESOLVE_DLL_REFERENCES LoadLibraryEx [
39         [
40             32768 ushort (c-array) [ 32768 GetModuleFileName drop ] keep
41             alien>native-string
42         ] [ FreeLibrary drop ] bi
43     ] [ f ] if* ;
44
45 PRIVATE>
46
47 M: windows find-library*
48     { [ find-library-paths ] [ find-library-file ] } 1|| ;