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);
42 $modules = 'modules'->new;
44 sub get_spec_file_type {
51 $module =~ s%^.*?([^/]+)\.spec$%$1%;
53 open(IN, "< $file") || die "$file: $!\n";
57 while($lookahead || defined($_ = <IN>)) {
64 if(/^\d+|@/) { $header = 0; $lookahead = 1; }
68 if(/^(\d+|@)\s+pascal(?:16)?/) {
79 return ($type, $module);
84 my $class = ref($proto) || $proto;
86 bless ($self, $class);
88 my $spec_files16 = \@{$self->{SPEC_FILES16}};
89 my $spec_files32 = \@{$self->{SPEC_FILES32}};
90 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
91 my $spec_file2dir = \%{$self->{SPEC_FILE2DIR}};
92 my $spec_file2module = \%{$self->{SPEC_FILE2MODULE}};
93 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
95 my $module_file = "$winapi_check_dir/modules.dat";
97 $output->progress("modules.dat");
103 open(IN, "< $module_file");
106 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begining and end of line
107 s/^(.*?)\s*#.*$/$1/; # remove comments
108 /^$/ && next; # skip empty lines
113 if(!-f "$wine_dir/$spec_file") {
114 $output->write("modules.dat: $spec_file: file ($spec_file) doesn't exist or is no file\n");
117 $spec_file_found{$spec_file}++;
118 $$spec_file2dir{$spec_file} = {};
122 $$spec_file2dir{$spec_file}{$allowed_dir}++;
124 $$dir2spec_file{$allowed_dir}{$spec_file}++;
126 if(!-d "$wine_dir/$allowed_dir") {
127 $output->write("modules.dat: $spec_file: directory ($allowed_dir) doesn't exist or is no directory\n");
133 if($wine_dir eq ".") {
134 @spec_files = get_spec_files("winelib");
137 foreach my $dir ($options->directories) {
138 $dir = "$current_dir/$dir";
140 foreach my $spec_file (sort(keys(%{$$dir2spec_file{$dir}}))) {
141 $spec_files{$spec_file}++;
144 @spec_files = sort(keys(%spec_files));
149 foreach my $spec_file (@spec_files) {
150 (my $type, my $module) = get_spec_file_type("$wine_dir/$spec_file");
152 $$spec_file2module{$spec_file} = $module;
153 $$module2spec_file{$module} = $spec_file;
155 if($type eq "win16") {
156 push @$spec_files16, $spec_file;
157 } elsif($type eq "win32") {
158 push @$spec_files32, $spec_file;
160 $output->write("$spec_file: unknown type '$type'\n");
164 foreach my $spec_file (@spec_files) {
165 if(!$spec_file_found{$spec_file} && $spec_file !~ m%tests/[^/]+$%) {
166 $output->write("modules.dat: $spec_file: exists but is not specified\n");
178 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
180 return sort(keys(%$module2spec_file));
183 sub complete_modules {
190 foreach my $file (@$c_files) {
191 my $dir = file_directory("$current_dir/$file");
195 my @c_files = get_c_files("winelib");
196 @c_files = files_skip(@c_files);
197 foreach my $file (@c_files) {
198 my $dir = file_directory($file);
199 if(exists($dirs{$dir})) {
204 my @complete_modules = ();
205 foreach my $module ($self->all_modules) {
207 my @dirs = $self->allowed_dirs_for_module($module);
208 foreach my $dir (@dirs) {
209 if(exists($dirs{$dir}) && $dirs{$dir} == 0) {
213 if($index == $#dirs) {
214 push @complete_modules, $module;
218 return @complete_modules;
221 sub is_allowed_module {
224 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
228 return defined($$module2spec_file{$module});
231 sub is_allowed_module_in_file {
234 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
235 my $spec_file2module = \%{$self->{SPEC_FILE2MODULE}};
242 $dir =~ s/\/[^\/]*$//;
244 if($dir =~ m%^include%) {
248 foreach my $spec_file (sort(keys(%{$$dir2spec_file{$dir}}))) {
249 if($$spec_file2module{$spec_file} eq $module) {
257 sub allowed_modules_in_file {
260 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
261 my $spec_file2module = \%{$self->{SPEC_FILE2MODULE}};
267 $dir =~ s/\/[^\/]*$//;
269 my %allowed_modules = ();
270 foreach my $spec_file (sort(keys(%{$$dir2spec_file{$dir}}))) {
271 my $module = $$spec_file2module{$spec_file};
272 $allowed_modules{$module}++;
275 my $module = join(" & ", sort(keys(%allowed_modules)));
280 sub allowed_dirs_for_module {
283 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
284 my $spec_file2dir = \%{$self->{SPEC_FILE2DIR}};
288 my $spec_file = $$module2spec_file{$module};
290 return sort(keys(%{$$spec_file2dir{$spec_file}}));
293 sub allowed_spec_files16 {
296 my $spec_files16 = \@{$self->{SPEC_FILES16}};
298 return @$spec_files16;
301 sub allowed_spec_files32 {
304 my $spec_files32 = \@{$self->{SPEC_FILES32}};
306 return @$spec_files32;
309 sub found_module_in_dir {
315 my $used_module_dirs = \%{$self->{USED_MODULE_DIRS}};
317 $dir = "$current_dir/$dir";
320 $$used_module_dirs{$module}{$dir}++;
326 my $dir2spec_file = \%{$self->{DIR2SPEC_FILE}};
327 my $module2spec_file = \%{$self->{MODULE2SPEC_FILE}};
328 my $used_module_dirs = \%{$self->{USED_MODULE_DIRS}};
331 foreach my $dir ($options->directories) {
332 $dir = "$current_dir/$dir";
334 foreach my $module ($self->all_modules) {
335 if(!$$used_module_dirs{$module}{$dir}) {
336 my $spec_file = $$module2spec_file{$module};
337 push @messages, "modules.dat: $spec_file: directory ($dir) is not used\n";
342 foreach my $message (sort(@messages)) {
343 $output->write($message);