Bugfixes, shellview uses DPA's now, IShellView_GetItemObject implemented.
[wine/multimedia.git] / tools / make_X11wrappers
blob1a1c08bd973a8bad8e48c38c9929455871c5f0b6
1 #!/usr/bin/perl -w
3 # Create threads safe wrappers around X11 calls.
5 # Copyright 1998 Kristian Nielsen.
8 # FIXME: This does not do full C prototype parsing, but relies on
9 # knowledge on how the X11 include files are formatted. It will
10 # probably need to be modified for new include files. It also fails
11 # for certain prototypes (notably those with function pointer
12 # arguments or results), so these must be added manually. And it
13 # relies on a fixed location of X11 includes (/usr/X11R6/include/).
15 # This program expects to be run from Wine's main directory.
17 $X11_include_dir = "/usr/X11R6/include";
18 $outdir = "tsx11";
19 $wantfile = "$outdir/X11_calls";
20 @dolist = ("Xlib", "Xresource", "Xutil", "xpm", "XShm", "xf86dga");
22 # First read list of wanted function names.
24 open(WANT, $wantfile) || die "open";
25 while(<WANT>) {
26 next if /^\s*\#/; # Skip comment lines.
27 next if /^\s*$/; # Skip empty lines.
28 if(/^\s*([a-zA-Z0-9_]+)\s*$/) {
29 $want{$1} = 1;
30 } else {
31 die "syntax error in file '$wantfile', in line '$_'";
34 close(WANT);
36 foreach $name (@dolist) {
38 $ucname = uc $name;
39 $lcname = lc $name;
41 $outfile = "/ts_$lcname";
42 open(OUTC, ">$outdir/$outfile.c") || die "open";
43 open(OUTH, ">include/$outfile.h") || die "open";
45 $x11_incl = "";
46 $extensions_dir = "";
47 $pre_file = "";
48 $post_file = "";
49 if($name eq "Xutil" || $name eq "Xresource" || $name eq "XShm") {
50 $x11_incl = "#include <X11/Xlib.h>\n";
51 # For Xutil, we need X11/Xresource.h for XUniqueContext().
52 $x11_incl .= "#include <X11/Xresource.h>\n" if $name eq "Xutil";
54 if($name eq "xf86dga") {
55 $x11_incl = "#include <X11/Xlib.h>\n";
56 $extensions_dir = "extensions/";
57 $pre_file = "#include \"config.h\"\n#ifdef HAVE_LIBXXF86DGA\n";
58 $post_file = "#endif";
60 if($name eq "XShm") {
61 $extensions_dir = "extensions/";
64 print OUTH <<END;
66 * Thread safe wrappers around $name calls.
67 * Always include this file instead of <X11/$name.h>.
68 * This file was generated automatically by tools/make_X11wrappers
70 * Copyright 1998 Kristian Nielsen
73 #ifndef __WINE_TS$ucname\_H
74 #define __WINE_TS$ucname\_H
76 $x11_incl#include <X11/$extensions_dir$name.h>
78 END
80 print OUTC <<END;
82 * Thread safe wrappers around $name calls.
83 * This file was generated automatically by tools/make_X11wrappers
84 * DO NOT EDIT!
86 $pre_file
87 $x11_incl#include <X11/$extensions_dir$name.h>
88 #include "x11drv.h"
89 #include "debug.h"
90 END
92 if($name eq "xpm") { # Handle as special case.
93 output_fn("XpmCreatePixmapFromData", "int",
94 "Display *, Drawable, char **, Pixmap *, Pixmap *, XpmAttributes *",
95 "Display *a0, Drawable a1, char **a2, Pixmap *a3, Pixmap *a4, XpmAttributes *a5",
96 "a0, a1, a2, a3, a4, a5");
97 output_fn("XpmAttributesSize", "int", "void", "void", "");
98 } elsif($name eq "XShm") {
99 output_fn("XShmQueryExtension", "Bool",
100 "Display *", "Display *a0", "a0");
101 output_fn("XShmPixmapFormat", "int",
102 "Display *", "Display *a0", "a0");
103 output_fn("XShmDetach", Status,
104 "Display *, XShmSegmentInfo *",
105 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
106 output_fn("XShmAttach", Status,
107 "Display *, XShmSegmentInfo *",
108 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
109 output_fn("XShmPutImage", Status,
110 "Display *, Drawable, GC, XImage *, int, int, int, int, unsigned int, unsigned int, Bool",
111 "Display *a0, Drawable a1, GC a2, XImage *a3, int a4, int a5, int a6, int a7, unsigned int a8, unsigned int a9, Bool a10", "a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10");
112 } elsif($name eq "xf86dga") {
113 output_fn("XF86DGAQueryVersion",Bool,
114 "Display*,int*,int*",
115 "Display*a0,int*a1,int*a2",
116 "a0,a1,a2"
118 output_fn("XF86DGAQueryExtension",Bool,
119 "Display*,int*,int*",
120 "Display*a0,int*a1,int*a2",
121 "a0,a1,a2"
123 output_fn("XF86DGAGetVideo",Status,
124 "Display*,int,char**,int*,int*,int*",
125 "Display*a0,int a1,char**a2,int*a3,int*a4,int*a5",
126 "a0,a1,a2,a3,a4,a5"
128 output_fn("XF86DGADirectVideo",Status,
129 "Display*,int,int",
130 "Display*a0,int a1,int a2",
131 "a0,a1,a2"
133 output_fn("XF86DGAGetViewPortSize",Status,
134 "Display*,int,int*,int*",
135 "Display*a0,int a1,int *a2,int *a3",
136 "a0,a1,a2,a3"
138 output_fn("XF86DGASetViewPort",Status,
139 "Display*,int,int,int",
140 "Display*a0,int a1,int a2,int a3",
141 "a0,a1,a2,a3"
143 output_fn("XF86DGAInstallColormap",Status,
144 "Display*,int,Colormap",
145 "Display*a0,int a1,Colormap a2",
146 "a0,a1,a2"
148 output_fn("XF86DGAQueryDirectVideo",Status,
149 "Display*,int,int*",
150 "Display*a0,int a1,int *a2",
151 "a0,a1,a2"
153 output_fn("XF86DGAViewPortChanged",Status,
154 "Display*,int,int",
155 "Display*a0,int a1,int a2",
156 "a0,a1,a2"
158 } else {
159 open(IN, "echo \"$x11_incl#include <X11/$extensions_dir$name.h>\" | gcc -L$X11_include_dir -E - | grep -v '^[ \t]*\$'|") || die "open";
161 PROTO: while(<IN>) {
162 if(m'extern\s+([^()]*)\b([a-zA-Z0-9_]+)\s*\(') {
163 $result_type = $1;
164 $fn_name = $2;
165 $result_type = "int" if $result_type =~ /^\s*$/;
166 @args = ();
167 while(<IN>) {
168 last if m'\)\s*;';
169 # Give up on vararg functions and function pointer args.
170 if(m'\.\.\.|\(\*\)') {
171 undef $fn_name;
172 last;
174 if(m'\s*([^,]*[^, \t])\s*(,?\n)') {
175 $args[$#args+1] = $1;
178 # Skip if vararg, function pointer arg, or not needed.
179 next unless $fn_name;
180 next unless $want{$fn_name} && $want{$fn_name} == 1;
182 # Special case for no arguments (which is specified as "void").
183 if($#args == 0 && $args[0] eq "void") {
184 @args = ();
186 $proto = "";
187 $formals = "";
188 $actuals = "";
189 for($i = 0; $i <= $#args; $i++) {
190 $comma = $i < $#args ? ", " : "";
191 $proto .= "$args[$i]$comma";
192 $formals .= "$args[$i] a$i$comma";
193 $actuals .= "a$i$comma";
195 $proto = $formals = "void" if $#args == -1;
196 output_fn($fn_name, $result_type, $proto, $formals, $actuals);
201 if($name eq "Xlib") {
202 raw_output_fn("XSynchronize", "int (*r)(Display *)",
203 "int (*TSXSynchronize(Display *, Bool))(Display *)",
204 "int (*TSXSynchronize(Display *a0, Bool a1))(Display *)",
205 "a0, a1");
206 print OUTC "\nextern void _XInitImageFuncPtrs(XImage *);\n";
207 output_fn("_XInitImageFuncPtrs", "void", "XImage *", "XImage *a0", "a0");
208 } elsif($name eq "Xutil") {
209 output_fn("XDestroyImage", "int",
210 "struct _XImage *", "struct _XImage *a0", "a0");
211 output_fn("XGetPixel", "unsigned long",
212 "struct _XImage *, int, int",
213 "struct _XImage *a0, int a1, int a2",
214 "a0, a1, a2");
215 output_fn("XPutPixel", "int",
216 "struct _XImage *, int, int, unsigned long",
217 "struct _XImage *a0, int a1, int a2, unsigned long a3",
218 "a0, a1, a2, a3");
219 output_fn("XSubImage", "struct _XImage *",
220 "struct _XImage *, int, int, unsigned int, unsigned int",
221 "struct _XImage *a0, int a1, int a2, unsigned int a3, unsigned int a4",
222 "a0, a1, a2, a3, a4");
223 output_fn("XAddPixel", "int",
224 "struct _XImage *, long",
225 "struct _XImage *a0, long a1", "a0, a1");
226 output_fn("XUniqueContext", "XContext", "void", "void", "");
229 print OUTH <<END;
231 #endif /* __WINE_TS$ucname\_H */
233 print OUTC <<END;
234 $post_file
241 foreach $i (keys %want) {
242 if($want{$i} == 1) {
243 print "Unresolved: $i\n";
248 sub output_fn {
249 # Example call:
250 # output_fn("main", "int", "int, char **", "int a0, char **a1", "a0, a1")
253 my ($fn_name, $result_type, $protos, $formals, $actuals) = @_;
255 return raw_output_fn($fn_name,
256 $result_type =~ /^\s*void\s*$/ ? "" : "$result_type r",
257 "$result_type TS$fn_name($protos)",
258 "$result_type TS$fn_name($formals)",
259 $actuals);
262 sub raw_output_fn {
263 # Example call:
264 # output_fn("main", "int r", "int main(int, char **)", "int main(int a0, char **a1)", "a0, a1")
267 my ($fn_name, $resultdecl, $protodecl, $defdecl, $actuals) = @_;
269 return undef unless $want{$fn_name} && $want{$fn_name} == 1;
271 print OUTC "\n$defdecl\n";
272 print OUTH "extern $protodecl;\n";
273 # print OUTH "#define $fn_name TS$fn_name\n";
274 print OUTC "{\n";
275 print OUTC " $resultdecl;\n" if $resultdecl;
276 print OUTC " TRACE(x11, \"Call $fn_name\\n\");\n";
277 print OUTC " EnterCriticalSection( &X11DRV_CritSection );\n";
278 print OUTC " ";
279 print OUTC "r = " if $resultdecl;
280 print OUTC "$fn_name($actuals);\n";
281 print OUTC " LeaveCriticalSection( &X11DRV_CritSection );\n";
282 print OUTC " TRACE(x11, \"Ret $fn_name\\n\");\n";
283 print OUTC " return r;\n" if $resultdecl;
284 print OUTC "}\n";
285 $want{$fn_name} = 2;
286 return 1;