Fixed winapi_extract.

diff --git a/tools/winapi/winapi_extract b/tools/winapi/winapi_extract
index bb509e9..013a2d8 100755
--- a/tools/winapi/winapi_extract
+++ b/tools/winapi/winapi_extract
@@ -41,20 +41,20 @@
 use type;
 use winapi_function;
 use winapi_parser;
-use winapi qw(@winapis);
+use winapi qw($win16api $win32api @winapis);
 
 my %module2entries;
 my %module2spec_file;
-my %module2type;
-my %module2filename;
 if($options->spec_files || $options->winetest) {
     local $_;
 
     foreach my $spec_file (get_spec_files("winelib")) {
 	my $entries = [];
 
-	my $module;
-	my $type;
+	my $module = $spec_file;
+	$module =~ s/^.*?([^\/]*)\.spec$/$1/;
+
+	my $type = "win32";
 
 	open(IN, "< $wine_dir/$spec_file");
 
@@ -68,16 +68,7 @@
 	    /^$/ && next;         # skip empty lines
 
 	    if($header)  {
-		if(/^name\s+(.*?)$/) {
-		    $module = $1;
-		    $module2spec_file{$module} = $spec_file;
-		} elsif(/^file\s+(.*?)$/) {
-		    my $filename = $1;
-		    $module2filename{$module} = $filename;
-		} elsif(/^type\s+(.*?)$/) {
-		    $type = $1;
-		    $module2type{$module} = $type;
-		} elsif(/^\d+|@/) {
+	        if(/^\d+|@/) {
 		    $header = 0;
 		    $lookahead = 1;
 		}
@@ -94,6 +85,7 @@
 	}
 	close(IN);
 
+	$module2spec_file{$module} = $spec_file;
 	$module2entries{$module} = $entries;
     }
 }
@@ -244,7 +236,15 @@
 	my $argument = shift;
     };
 
-    &winapi_parser::parse_c_file($file, $create_function, $found_function, $create_type, $found_type, $found_preprocessor);
+    &winapi_parser::parse_c_file($file, {
+	# c_comment_found => $found_c_comment,
+	# cplusplus_comment_found => $found_cplusplus_comment,
+	function_create => $create_function,
+	function_found => $found_function,
+	type_create => $create_type,
+	type_found => $found_type,
+	preprocessor_found => $found_preprocessor
+    });
 
     my @internal_names = keys(%functions);
     if($#internal_names < 0) {
@@ -283,107 +283,113 @@
 }
 
 if($options->spec_files) {
-    foreach my $module (keys(%specifications)) {
-	my $spec_file = $module2spec_file{$module};
-	my $type = $module2type{$module};
+    foreach my $winapi (@winapis) {
+	my $type = $winapi->name;
 
-	if(!defined($spec_file) || !defined($type)) {
-	    $output->write("$module: doesn't exist\n");
-	    next;
-	}
+	if($type eq "win16" && !$options->win16) { next; }
+	if($type eq "win32" && !$options->win32) { next; }
 
-	$spec_file .= "2";
+	foreach my $module ($winapi->all_modules) {
+	    my $spec_file = $module2spec_file{$module};
 
-	$output->progress("$spec_file");
-	open(OUT, "> $wine_dir/$spec_file");
-
-	print OUT "name $module\n";
-	print OUT "type $type\n";
-	if(exists($specifications{$module}{init})) {
-	    my $function = $specifications{$module}{init}{function};
-	    print OUT "init " . $function->internal_name . "\n";
-	}
-	print OUT "\n";
-
-	my %debug_channels;
-	if(exists($specifications{$module}{init})) {
-	    my $function = $specifications{$module}{init}{function};
-	    foreach my $debug_channel (@{$function->debug_channels}) {
-		$debug_channels{$debug_channel}++;
+	    if(!defined($spec_file) || !defined($type)) {
+		$output->write("$module: doesn't exist\n");
+		next;
 	    }
-	}
-	foreach my $ordinal (sort {$a <=> $b} keys(%{$specifications{$module}{fixed}})) {
-	    my $function = $specifications{$module}{fixed}{$ordinal}{function};
-	    foreach my $debug_channel (@{$function->debug_channels}) {
-		$debug_channels{$debug_channel}++;
+
+	    $spec_file .= "2";
+
+	    $output->progress("$spec_file");
+	    open(OUT, "> $wine_dir/$spec_file");
+
+	    if(exists($specifications{$module}{init})) {
+		my $function = $specifications{$module}{init}{function};
+		print OUT "init " . $function->internal_name . "\n";
 	    }
-	}
-	foreach my $name (sort(keys(%{$specifications{$module}{unfixed}}))) {
-	    my $function = $specifications{$module}{unfixed}{$name}{function};
-	    foreach my $debug_channel (@{$function->debug_channels}) {
-		$debug_channels{$debug_channel}++;
+	    print OUT "\n";
+
+	    my %debug_channels;
+	    if(exists($specifications{$module}{init})) {
+		my $function = $specifications{$module}{init}{function};
+		foreach my $debug_channel (@{$function->debug_channels}) {
+		    $debug_channels{$debug_channel}++;
+		}
 	    }
-	}
-	foreach my $name (sort(keys(%{$specifications{$module}{unknown}}))) {
-	    my $function = $specifications{$module}{unknown}{$name}{function};
-	    foreach my $debug_channel (@{$function->debug_channels}) {
-		$debug_channels{$debug_channel}++;
+	    foreach my $ordinal (sort {$a <=> $b} keys(%{$specifications{$module}{fixed}})) {
+		my $function = $specifications{$module}{fixed}{$ordinal}{function};
+		foreach my $debug_channel (@{$function->debug_channels}) {
+		    $debug_channels{$debug_channel}++;
+		}
 	    }
-	}
+	    foreach my $name (sort(keys(%{$specifications{$module}{unfixed}}))) {
+		my $function = $specifications{$module}{unfixed}{$name}{function};
+		foreach my $debug_channel (@{$function->debug_channels}) {
+		    $debug_channels{$debug_channel}++;
+		}
+	    }
+	    foreach my $name (sort(keys(%{$specifications{$module}{unknown}}))) {
+		my $function = $specifications{$module}{unknown}{$name}{function};
+		foreach my $debug_channel (@{$function->debug_channels}) {
+		    $debug_channels{$debug_channel}++;
+		}
+	    }
 
-	my @debug_channels = sort(keys(%debug_channels));
-	if($#debug_channels >= 0) {
-	    print OUT "debug_channels (" .  join(" ", @debug_channels) . ")\n";
-	    print OUT "\n";
-	}
+	    my @debug_channels = sort(keys(%debug_channels));
+	    if($#debug_channels >= 0) {
+		print OUT "debug_channels (" .  join(" ", @debug_channels) . ")\n";
+		print OUT "\n";
+	    }
 
-	my $empty = 1;
+	    my $empty = 1;
 
-	if(!$empty) {
-	    print OUT "\n";
-	    $empty = 1;
-	}
-	foreach my $external_name (sort(keys(%{$specifications{$module}{unknown}}))) {
-	    my $entry = $specifications{$module}{unknown}{$external_name};
-	    my $ordinal = $entry->{ordinal};
-	    my $function = $entry->{function};
-	    print OUT "# ";
-	    output_function(\*OUT, $type, $ordinal, $external_name, $function);
-	    $empty = 0;
-	}
+	    if(!$empty) {
+		print OUT "\n";
+		$empty = 1;
+	    }
+	    foreach my $external_name (sort(keys(%{$specifications{$module}{unknown}}))) {
+		my $entry = $specifications{$module}{unknown}{$external_name};
+		my $ordinal = $entry->{ordinal};
+		my $function = $entry->{function};
+		print OUT "# ";
+		output_function(\*OUT, $type, $ordinal, $external_name, $function);
+		$empty = 0;
+	    }
 
-	if(!$empty) {
-	    print OUT "\n";
-	    $empty = 1;
-	}
-	foreach my $ordinal (sort {$a <=> $b} keys(%{$specifications{$module}{fixed}})) {
-	    my $entry = $specifications{$module}{fixed}{$ordinal};
-	    my $external_name = $entry->{external_name};
-	    my $function = $entry->{function};
-	    output_function(\*OUT, $type, $ordinal, $external_name, $function);
-	    $empty = 0;
-	}
+	    if(!$empty) {
+		print OUT "\n";
+		$empty = 1;
+	    }
+	    foreach my $ordinal (sort {$a <=> $b} keys(%{$specifications{$module}{fixed}})) {
+		my $entry = $specifications{$module}{fixed}{$ordinal};
+		my $external_name = $entry->{external_name};
+		my $function = $entry->{function};
+		output_function(\*OUT, $type, $ordinal, $external_name, $function);
+		$empty = 0;
+	    }
 
-	if(!$empty) {
-	    print OUT "\n";
-	    $empty = 1;
-	}
-	foreach my $external_name (sort(keys(%{$specifications{$module}{unfixed}}))) {
-	    my $entry = $specifications{$module}{unfixed}{$external_name};
-	    my $ordinal = $entry->{ordinal};
-	    my $function = $entry->{function};
-	    output_function(\*OUT, $type, $ordinal, $external_name, $function);
-	    $empty = 0;
-	}
+	    if(!$empty) {
+		print OUT "\n";
+		$empty = 1;
+	    }
+	    foreach my $external_name (sort(keys(%{$specifications{$module}{unfixed}}))) {
+		my $entry = $specifications{$module}{unfixed}{$external_name};
+		my $ordinal = $entry->{ordinal};
+		my $function = $entry->{function};
+		output_function(\*OUT, $type, $ordinal, $external_name, $function);
+		$empty = 0;
+	    }
 
-	close(OUT);
+	    close(OUT);
+	}
     }
 }
 
 if($options->stub_statistics) {
     foreach my $winapi (@winapis) {
-	if($winapi->name eq "win16" && !$options->win16) { next; }
-	if($winapi->name eq "win32" && !$options->win32) { next; }
+	my $type = $winapi->name;
+
+	if($type eq "win16" && !$options->win16) { next; }
+	if($type eq "win32" && !$options->win32) { next; }
 
 	my %module_stub_count;
 	my %module_total_count;
@@ -421,13 +427,12 @@
 }
 
 if($options->winetest) {
-    foreach my $module (sort(keys(%specifications))) {
-	my $type = $module2type{$module};
-        my $filename = $module2filename{$module} || $module;
-        my $modulename = $filename;
-        $modulename =~ s/\./_/g;
+    foreach my $module ($win32api->all_modules) {
+	my $type = "win32";
 
-	next unless $type eq "win32";
+        my $package = $module;
+	$package =~ s/\.dll$//;
+        $package =~ s/\./_/g;
 
 	my @entries;
 
@@ -452,18 +457,9 @@
 	    my $ordinal = $entry->{ordinal};
 	    my $function = $entry->{function};
 
-	    my $return_kind;
-	    my $calling_convention;
-	    my $refargument_kinds;
-	    if($type eq "win16") {
-		$return_kind = $function->return_kind16 || "undef";
-		$calling_convention = $function->calling_convention16 || "undef";
-		$refargument_kinds = $function->argument_kinds16;
-	    } elsif($type eq "win32") {
-		$return_kind = $function->return_kind32 || "undef";
-		$calling_convention = $function->calling_convention32 || "undef";
-		$refargument_kinds = $function->argument_kinds32;
-	    }
+	    my $return_kind = $function->return_kind32 || "undef";
+	    my $calling_convention = $function->calling_convention32 || "undef";
+	    my $refargument_kinds = $function->argument_kinds32;
 
 	    my @argument_kinds;
 	    if(defined($refargument_kinds)) {
@@ -474,9 +470,9 @@
 	    next if $external_name eq "\@";
 
 	    if($n == 0) {
-                open(OUT, "> $wine_dir/programs/winetest/include/${modulename}.pm");
+                open(OUT, "> $wine_dir/programs/winetest/include/${package}.pm");
 
-                print OUT "package ${modulename};\n";
+                print OUT "package ${package};\n";
                 print OUT "\n";
 
                 print OUT "use strict;\n";
@@ -516,7 +512,7 @@
 	    print OUT "\n";
 	    print OUT "};\n";
 	    print OUT "\n";
-            print OUT "&wine::declare(\"$filename\",\%\$module_declarations);\n";
+            print OUT "&wine::declare(\"$module\",\%\$module_declarations);\n";
             print OUT "push \@EXPORT, map { \"&\" . \$_; } sort(keys(\%\$module_declarations));\n";
 	    print OUT "1;\n";
             close(OUT);