Reimplemented Unicode case mapping in a slightly more efficient way.
[wine] / dlls / opengl32 / make_opengl_ext
1 #!/usr/bin/perl -w
2
3 print "
4 /* Auto-generated file... Do not edit ! */
5
6 #include \"config.h\"
7 #include \"wine_gl.h\"
8
9 #include \"opengl_ext.h\"
10
11 ";
12
13 #
14 # First, create a hash-table with all function defined in opengl32.spec
15 #
16 %opengl_std = ();
17 open(SPEC, "dlls/opengl32/opengl32.spec") || die "Could not open spec file";
18 foreach (<SPEC>) {
19     if (($_ =~ /@/) && ($_ !~ /wgl/)) {
20         ($name) = ($_ =~ /stdcall (\w*)\(/);
21         $opengl_std{$name} = 1;
22     }
23 }
24 close(SPEC);
25
26 #
27 # Now, the functions from the include file
28 #
29 %opengl_ext = ();
30 open(INC, "/home/ulmer/OpenGL/glext_proto.h") || die "Could not open GL/glext.h";
31 while ($line = <INC>) {
32     if ($line =~ /extern.*APIENTRY/) {
33         # Start of a function declaration
34         ($ret, $name, $args) = ($line =~ /extern (\w*) APIENTRY *(\w*) *\((.*)\)/);
35         
36         # Now, remove all function already defined in opengl32.spec
37         if ($opengl_std{$name}) {
38             # Do nothing as we already have these functions
39         } else {
40             # Now, get the typedef name (the line after)
41             ($typedef_name) = (<INC> =~ /\(APIENTRY *\* *(\w*) *\)/);
42
43             # After that, parse the arguments
44             @args = split /,/, $args;
45             $args_ref = [];
46             foreach (@args) {
47                 push @$args_ref, $_;
48             }
49             $opengl_ext{$name} = [ $ret, $typedef_name, $args_ref ];
50         }
51     }
52 }
53 close(INC);
54
55 #
56 # After that, generate the file itself....
57 #
58 print "/* These will be filled during a wglGetProcAddress call */\n";
59 $num = 0;
60 foreach $name (sort keys(%opengl_ext)) {
61     $ref = $opengl_ext{$name};
62     $arg_ref = $$ref[2];
63     @larg = @$arg_ref;
64
65     print "$$ref[0] (*func_$name)(";
66     $farg = shift @larg;
67     print "$farg";
68     foreach (@larg) {
69         print ", $_";
70     }    
71     print ") = (void *) 0xdeadbeef;\n";
72     $num++;
73 }
74 print "\n";
75
76 print "/* The function prototypes */\n";
77 foreach $name (sort keys(%opengl_ext)) {
78     $ref = $opengl_ext{$name};
79     $arg_ref = $$ref[2];
80     @larg = @$arg_ref;
81     print "$$ref[0] WINAPI wine_$name(";
82
83     $farg = shift @larg;
84     print "$farg";
85     foreach (@larg) {
86         print ", $_";
87     }
88     print ") ;\n";
89 }
90 print "\n";
91
92
93 print "/* The table giving the correspondance between names and functions */\n";
94 print "int extension_registry_size = $num;\n";
95 print "OpenGL_extension extension_registry[] = {\n";
96 foreach $name (sort keys(%opengl_ext)) {
97     $num--;
98     print "  { \"$name\", (void *) wine_$name, (void **) (&func_$name) }";
99     if ($num) {
100         print ",";
101     }
102     print "\n";
103 }
104 print "};\n";
105 print "\n";
106
107 print "/* Now, the function declarations */\n";
108 foreach $name (sort keys(%opengl_ext)) {
109     $ref = $opengl_ext{$name};
110     $arg_ref = $$ref[2];
111     print "$$ref[0] WINAPI wine_$name(";
112
113     $farg = shift @$arg_ref;
114     $num = 0;
115     if ($farg !~ /void/) {
116         print "$farg arg_0";
117         $num++;
118         foreach (@$arg_ref) {
119             print ", $_ arg_$num";
120             $num++;
121         }
122     }
123     print ") {\n";
124     if ($$ref[0] !~ /void/) {
125         print "  $$ref[0] ret;\n"
126     }
127     print "  ENTER_GL();\n";
128     print "  ";
129     if ($$ref[0] !~ /void/) {
130         print "  ret = ";
131     }
132     print "func_$name(";
133     if ($num > 0) {
134         print "arg_0";
135         for ($i = 1; $i < $num; $i++) {
136             print ", arg_$i";
137         }
138     }
139     print ");\n";
140     print "  LEAVE_GL();\n";
141     if ($$ref[0] !~ /void/) {
142         print "  return ret;\n"
143     }
144     print "}\n\n";
145 }