Added Perl modules containing the #defines values for the
[wine] / programs / winetest / make_symbols
1 #!/usr/bin/perl -w
2 #
3 # Extract #define symbol information from C header files.
4 #
5 # Copyright 2002 Alexandre Julliard
6 #
7
8 # list of symbols (regexps) to skip for each header
9 %skip_list =
10 (
11  "winnt.h"   => [ "APIENTRY", "APIPRIVATE", "CALLBACK", "CONST", "EXTERN_C", "PASCAL",
12                   "VOID", "DUMMY(STRUCT|UNION)NAME.*", "STDAPI.*", "STDMETHOD.*", "WINAPI.*",
13                   "WINE_.*", "_*(cdecl|CDECL|pascal|export|fastcall|stdcall)",
14                   "MEM_SYSTEM", "_GET_CONTEXT", "_QUAD_.*",
15                   "CONTEXT_(ALPHA|R4000|SPARC|X86|i386|i486)" ],
16  "winbase.h" => [ "(Fill|Move|Zero|Copy)Memory" ],
17  "wingdi.h"  => [ "PROFILE_LINKED", "PROFILE_EMBEDDED", "GetCharWidth[AW]" ],
18  "winuser.h" => [ "OemToAnsi[AW]", "OemToAnsiBuff[AW]", "AnsiToOem[AW]", "AnsiToOemBuff[AW]",
19                   "Ansi(Next|Prev|Lower|Upper|LowerBuff|UpperBuff)[AW]", "GetNextWindow" ],
20  "winsock2.h" => [ "WSAEVENT", "LPWSAEVENT", "WSAOVERLAPPED", "WS_.*" ]
21 );
22
23 @header_list =
24 (
25  "windef.h",
26  "winnt.h",
27  "winbase.h",
28  "wingdi.h",
29  "winuser.h",
30  "winerror.h",
31  "winnls.h",
32  "winreg.h",
33  "winsock2.h",
34  "winspool.h",
35  "winver.h",
36  "wincon.h",
37 );
38
39 $include_dir = "../../include";
40
41 @list = ($#ARGV >= 0) ? @ARGV : @header_list;
42
43 foreach $basename (@list)
44 {
45     my $skip = $skip_list{$basename};
46     my $result = "include/" . $basename;
47     $result =~ s!\.h$!.pm!;
48
49     open INPUT, "$include_dir/$basename" or die "Cannot open $include_dir/$basename";
50     open OUTPUT, ">sym.c" or die "Cannot create sym.c";
51     print "Building $result\n";
52
53     print OUTPUT <<EOF;
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <limits.h>
57 EOF
58     foreach $inc (@header_list) { print OUTPUT "#include <$inc>\n"; }
59
60     print OUTPUT <<EOF;
61 int main()
62 {
63     printf( "# Automatically generated by make_symbols; DO NOT EDIT!! \\n" );
64     printf( "#\\n" );
65     printf( "# Perl definitions for header file $basename\\n" );
66     printf( "#\\n\\n" );
67 EOF
68
69     my %symbols = ();
70     while (<INPUT>)
71     {
72         # extract all #defines
73         next unless (/^\s*\#\s*define\s+([A-Za-z0-9_]+)\s+(.*)$/);
74         my ($name,$value) = ($1,$2);
75         # skip empty value
76         next if ($value eq "");
77         # skip the WINELIB defines
78         next if ($value =~ /WINELIB_NAME_AW/);
79         # skip macros containing multiple values
80         next if ($value =~ /{.*}/);
81         # check against regexps to skip
82         next if (grep { $name =~ /^$_$/ } @$skip);
83         $symbols{$name} = $value;
84     }
85     foreach $sym (sort keys %symbols)
86     {
87         printf OUTPUT "    printf(\"\$$sym = %%d;\\n\", (int)($sym));\n";
88     }
89     print OUTPUT "    exit(0);\n}\n";
90     close OUTPUT;
91     #print "cc -I../../include -o sym sym.c\n";
92     if (system( "cc -I../../include -o sym sym.c" )) { die "Could not compile sym.c"; }
93     #print "./sym >$result\n";
94     if (system( "./sym >$result" )) { die "Could not run ./sym\n"; }
95     unlink "sym","sym.c";
96 }