dinput: Move SetEventNotification and associated event into base class.
[wine] / tools / winapi / config.pm
1 #
2 # Copyright 1999, 2000, 2001 Patrik Stridvall
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 #
18
19 package config;
20
21 use strict;
22
23 use setup qw($current_dir $wine_dir $winapi_dir);
24
25 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
26 require Exporter;
27
28 @ISA = qw(Exporter);
29 @EXPORT = qw(
30     file_absolutize file_normalize
31     file_directory
32     file_type files_filter
33     file_skip files_skip
34     get_c_files
35     get_h_files
36     get_makefile_in_files
37     get_spec_files
38 );
39 @EXPORT_OK = qw(
40     $current_dir $wine_dir $winapi_dir
41 );
42
43 use vars qw($current_dir $wine_dir $winapi_dir);
44
45 use output qw($output);
46
47 use File::Find;
48
49 sub file_normalize($) {
50     local $_ = shift;
51
52     foreach my $dir (split(m%/%, $current_dir)) {
53         if(s%^(\.\./)*\.\./$dir/%%) {
54             if(defined($1)) {
55                 $_ = "$1$_";
56             }
57         }
58     }
59
60     while(m%^(.*?)([^/\.]+)/\.\./(.*?)$%) {
61         if($2 ne "." && $2 ne "..") {
62             $_ = "$1$3";
63         }
64     }
65
66     return $_;
67 }
68
69 sub file_absolutize($) {
70     local $_ = shift;
71
72     $_ = file_normalize($_);
73     if(!s%^$wine_dir/%%) {
74         $_ = "$current_dir/$_";
75     }
76     s%^\./%%;
77
78     return $_;
79 }
80
81 sub file_type($) {
82     local $_ = shift;
83
84     $_ = file_absolutize($_);
85
86     m%^(?:server|tests|tools)/% && return "";
87     m%^(?:programs)/% && return "wineapp";
88     m%^(?:libs)/% && return "library";
89
90     return "winelib";
91 }
92
93 sub files_filter($@) {
94     my $type = shift;
95
96     my @files;
97     foreach my $file (@_) {
98         if(file_type($file) eq $type) {
99             push @files, $file;
100         }
101     }
102
103     return @files;
104 }
105
106 sub file_skip($) {
107     local $_ = shift;
108
109     $_ = file_absolutize($_);
110
111     m%^(?:loader|libs|programs|server|tools)/% && return 1;
112     m%^dlls/wineps/data/% && return 1;
113     m%^dlls/winmm/wineoss/midipatch\.c$% && return 1;
114     m%spec\.c$% && return 1;
115
116     return 0;
117 }
118
119 sub files_skip(@) {
120     my @files;
121     foreach my $file (@_) {
122         if(!file_skip($file)) {
123             push @files, $file;
124         }
125     }
126
127     return @files;
128 }
129
130 sub file_directory($) {
131     local $_ = shift;
132
133     s%/?[^/]*$%%;
134     if(!$_) {
135         $_ = ".";
136     }
137
138     s%^(?:\./)?(.*?)(?:/\.)?%$1%;
139
140     return $_;
141 }
142
143 sub _get_files($$;$) {
144     my $pattern = shift;
145     my $type = shift;
146     my $dir = shift;
147
148     $output->progress("$wine_dir: searching for /$pattern/");
149
150     if(!defined($dir)) {
151         $dir = $wine_dir;
152     }
153
154     my @files;
155
156     my @dirs = ($dir);
157     while(defined(my $dir = shift @dirs)) {
158         opendir(DIR, $dir) || die "Can't open directory $dir: $!\n";
159         my @entries= readdir(DIR);
160         closedir(DIR);
161         foreach (@entries) {
162             my $basefile = $_;
163             $_ = "$dir/$_";
164             if(/\.\.?$/) {
165                 # Nothing
166             } elsif(-d $_) {
167                 push @dirs, $_;
168             } elsif($basefile =~ /$pattern/ && (!defined($type) || file_type($_) eq $type)) {
169                 s%^$wine_dir/%%;
170                 push @files, $_;
171             }
172         }
173     }
174
175     return @files;
176 }
177
178 sub get_c_files($;$) { return _get_files('\.c$', $_[0], $_[1]); }
179 sub get_h_files($;$) { return _get_files('\.h$', $_[0], $_[1]); }
180 sub get_spec_files($;$) { return _get_files('\.spec$', $_[0], $_[1]); }
181 sub get_makefile_in_files($;$) { return _get_files('^Makefile.in$', $_[0], $_[1]); }
182
183 1;