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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
28 @EXPORT_OK = qw($modules);
30 use vars qw($modules);
33 &file_type &files_skip
35 &get_c_files &get_spec_files
36 $current_dir $wine_dir
39 use options qw($options);
40 use output qw($output);
43 $Exporter::ExportLevel++;
44 &Exporter::import(@_);
45 $Exporter::ExportLevel--;
47 if (defined($modules)) {
51 $modules = 'modules'->new;
54 sub get_spec_file_type {
61 $module =~ s%^.*?([^/]+)\.spec$%$1%;
63 open(IN, "< $file") || die "$file: $!\n";
67 while($lookahead || defined($_ = <IN>)) {
74 if(/^\d+|@/) { $header = 0; $lookahead = 1; }
78 if(/^(\d+|@)\s+pascal(?:16)?/) {
89 return ($type, $module);
94 my $class = ref($proto) || $proto;
96 bless ($self, $class);
98 my $spec_file_found = $self->find_spec_files();
99 $self->read_spec_files($spec_file_found);
104 sub find_spec_files {
107 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
108 my $spec_file2dir = \%{$self->{SPEC_FILE2DIR}};
110 $output->progress("modules");
112 my $spec_file_found = {};
116 my @spec_files = <{dlls/*/*.spec,dlls/*/*/*.spec}>;
118 foreach $spec_file (@spec_files) {
119 $spec_file =~ /(.*)\/.*\.spec/;
123 $$spec_file_found{$spec_file}++;
124 $$spec_file2dir{$spec_file}{$allowed_dir}++;
125 $$dir2spec_file{$allowed_dir}{$spec_file}++;
128 return $spec_file_found;
131 sub read_spec_files {
134 my $spec_file_found = shift;
136 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
137 my $spec_files16 = \@{$self->{SPEC_FILES16}};
138 my $spec_files32 = \@{$self->{SPEC_FILES32}};
139 my $spec_file2module = \%{$self->{SPEC_FILE2MODULE}};
140 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
143 if($wine_dir eq ".") {
144 @spec_files = get_spec_files("winelib");
147 foreach my $dir ($options->directories) {
148 $dir = "$current_dir/$dir";
150 foreach my $spec_file (sort(keys(%{$$dir2spec_file{$dir}}))) {
151 $spec_files{$spec_file}++;
154 @spec_files = sort(keys(%spec_files));
159 foreach my $spec_file (@spec_files) {
160 (my $type, my $module) = get_spec_file_type("$wine_dir/$spec_file");
162 $$spec_file2module{$spec_file} = $module;
163 $$module2spec_file{$module} = $spec_file;
165 if($type eq "win16") {
166 push @$spec_files16, $spec_file;
167 } elsif($type eq "win32") {
168 push @$spec_files32, $spec_file;
170 $output->write("$spec_file: unknown type '$type'\n");
174 foreach my $spec_file (@spec_files) {
175 if(!$$spec_file_found{$spec_file} && $spec_file !~ m%tests/[^/]+$%) {
176 $output->write("modules: $spec_file: exists but is not specified\n");
184 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
186 return sort(keys(%$module2spec_file));
189 sub complete_modules {
196 foreach my $file (@$c_files) {
197 my $dir = file_directory("$current_dir/$file");
201 my @c_files = get_c_files("winelib");
202 @c_files = files_skip(@c_files);
203 foreach my $file (@c_files) {
204 my $dir = file_directory($file);
205 if(exists($dirs{$dir})) {
210 my @complete_modules = ();
211 foreach my $module ($self->all_modules) {
213 my @dirs = $self->allowed_dirs_for_module($module);
214 foreach my $dir (@dirs) {
215 if(exists($dirs{$dir}) && $dirs{$dir} == 0) {
219 if($index == $#dirs) {
220 push @complete_modules, $module;
224 return @complete_modules;
227 sub is_allowed_module {
230 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
234 return defined($$module2spec_file{$module});
237 sub is_allowed_module_in_file {
240 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
241 my $spec_file2module = \%{$self->{SPEC_FILE2MODULE}};
248 $dir =~ s/\/[^\/]*$//;
250 if($dir =~ m%^include%) {
254 foreach my $spec_file (sort(keys(%{$$dir2spec_file{$dir}}))) {
255 if($$spec_file2module{$spec_file} eq $module) {
263 sub allowed_modules_in_file {
266 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
267 my $spec_file2module = \%{$self->{SPEC_FILE2MODULE}};
273 $dir =~ s/\/[^\/]*$//;
275 my %allowed_modules = ();
276 foreach my $spec_file (sort(keys(%{$$dir2spec_file{$dir}}))) {
277 my $module = $$spec_file2module{$spec_file};
278 $allowed_modules{$module}++;
281 my $module = join(" & ", sort(keys(%allowed_modules)));
286 sub allowed_dirs_for_module {
289 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
290 my $spec_file2dir = \%{$self->{SPEC_FILE2DIR}};
294 my $spec_file = $$module2spec_file{$module};
296 return sort(keys(%{$$spec_file2dir{$spec_file}}));
299 sub allowed_spec_files16 {
302 my $spec_files16 = \@{$self->{SPEC_FILES16}};
304 return @$spec_files16;
307 sub allowed_spec_files32 {
310 my $spec_files32 = \@{$self->{SPEC_FILES32}};
312 return @$spec_files32;
315 sub found_module_in_dir {
321 my $used_module_dirs = \%{$self->{USED_MODULE_DIRS}};
323 $dir = "$current_dir/$dir";
326 $$used_module_dirs{$module}{$dir}++;
332 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
333 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
334 my $used_module_dirs = \%{$self->{USED_MODULE_DIRS}};
337 foreach my $dir ($options->directories) {
338 $dir = "$current_dir/$dir";
340 foreach my $module ($self->all_modules) {
341 if(!$$used_module_dirs{$module}{$dir}) {
342 my $spec_file = $$module2spec_file{$module};
343 push @messages, "modules: $spec_file: directory ($dir) is not used\n";
348 foreach my $message (sort(@messages)) {
349 $output->write($message);