mfplay: Handle user sinks.
[wine.git] / tools / winapi / config.pm
blobceba90a4851091494ffb2fb4a2469fc52337ade2
2 # Copyright 1999, 2000, 2001 Patrik Stridvall
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.
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.
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
19 package config;
21 use strict;
22 use warnings 'all';
24 use setup qw($current_dir $wine_dir $winapi_dir);
26 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
27 require Exporter;
29 @ISA = qw(Exporter);
30 @EXPORT = qw(
31 file_absolutize file_normalize
32 file_directory
33 file_type files_filter
34 file_skip files_skip
35 get_c_files
36 get_h_files
37 get_makefile_in_files
38 get_spec_files
40 @EXPORT_OK = qw(
41 $current_dir $wine_dir $winapi_dir
44 use vars qw($current_dir $wine_dir $winapi_dir);
46 use output qw($output);
48 use File::Find;
50 sub file_normalize($) {
51 local $_ = shift;
53 foreach my $dir (split(m%/%, $current_dir)) {
54 if(s%^(\.\./)*\.\./$dir/%%) {
55 if(defined($1)) {
56 $_ = "$1$_";
61 while(m%^(.*?)([^/\.]+)/\.\./(.*?)$%) {
62 if($2 ne "." && $2 ne "..") {
63 $_ = "$1$3";
67 return $_;
70 sub file_absolutize($) {
71 local $_ = shift;
73 $_ = file_normalize($_);
74 if(!s%^$wine_dir/%%) {
75 $_ = "$current_dir/$_";
77 s%^\./%%;
79 return $_;
82 sub file_type($) {
83 local $_ = shift;
85 $_ = file_absolutize($_);
87 m%^(?:server|tests|tools)/% && return "";
88 m%^(?:programs)/% && return "wineapp";
89 m%^(?:libs)/% && return "library";
91 return "winelib";
94 sub files_filter($@) {
95 my $type = shift;
97 my @files;
98 foreach my $file (@_) {
99 if(file_type($file) eq $type) {
100 push @files, $file;
104 return @files;
107 sub file_skip($) {
108 local $_ = shift;
110 $_ = file_absolutize($_);
112 m%^(?:dlls|include)/% || return 1;
113 m%^dlls/wineps\.drv/data/% && return 1;
114 return 0;
117 sub files_skip(@) {
118 my @files;
119 foreach my $file (@_) {
120 if(!file_skip($file)) {
121 push @files, $file;
125 return @files;
128 sub file_directory($) {
129 local $_ = shift;
131 s%/?[^/]*$%%;
132 if(!$_) {
133 $_ = ".";
136 s%^(?:\./)?(.*?)(?:/\.)?%$1%;
138 return $_;
141 sub _get_files($$;$) {
142 my $pattern = shift;
143 my $type = shift;
144 my $dir = shift;
146 $output->progress("$wine_dir: searching for /$pattern/");
148 if(!defined($dir)) {
149 $dir = $wine_dir;
152 my @files;
154 my @dirs = ($dir);
155 while(defined(my $dir = shift @dirs)) {
156 opendir(DIR, $dir) || die "Can't open directory $dir: $!\n";
157 my @entries= readdir(DIR);
158 closedir(DIR);
159 foreach (@entries) {
160 my $basefile = $_;
161 $_ = "$dir/$_";
162 if(/\.\.?$/) {
163 # Nothing
164 } elsif(-d $_) {
165 push @dirs, $_;
166 } elsif($basefile =~ /$pattern/ && (!defined($type) || file_type($_) eq $type)) {
167 s%^$wine_dir/%%;
168 push @files, $_;
173 return @files;
176 sub get_c_files($;$) { return _get_files('\.c$', $_[0], $_[1]); }
177 sub get_h_files($;$) { return _get_files('\.h$', $_[0], $_[1]); }
178 sub get_spec_files($;$) { return _get_files('\.spec$', $_[0], $_[1]); }
179 sub get_makefile_in_files($;$) { return _get_files('^Makefile.in$', $_[0], $_[1]); }