Fixed copying of the MDI 'Windows' menu items if the items are not of
[wine/multimedia.git] / tools / make_X11wrappers
blob61b5c23f26967dadea99e918729da56d342221f9
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/X11/include";
18 $outdir = "tsx11";
19 $wantfile = "$outdir/X11_calls";
20 @dolist = ("Xlib", "Xresource", "Xutil", "xpm", "XShm", "xf86dga", "xf86dga2", "xf86vmode");
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 $inc_name = $name;
50 if($name eq "Xutil" || $name eq "Xresource" || $name eq "XShm") {
51 $x11_incl = "#include <X11/Xlib.h>\n";
52 # For Xutil, we need X11/Xresource.h for XUniqueContext().
53 $x11_incl .= "#include <X11/Xresource.h>\n" if $name eq "Xutil";
55 if($name eq "xf86dga") {
56 $x11_incl = "#include <X11/Xlib.h>\n";
57 $extensions_dir = "extensions/";
58 $pre_file = "#ifdef HAVE_LIBXXF86DGA\n";
59 $post_file = "#endif /* defined(HAVE_LIBXXF86DGA) */\n";
61 if($name eq "xf86dga2") {
62 $x11_incl = "#include <X11/Xlib.h>\n";
63 $extensions_dir = "extensions/";
64 $pre_file = "#ifdef HAVE_LIBXXF86DGA2\n";
65 $post_file = "#endif /* defined(HAVE_LIBXXF86DGA2) */\n";
66 $inc_name = "xf86dga";
68 if($name eq "XShm") {
69 $extensions_dir = "extensions/";
70 $pre_file = "#ifdef HAVE_LIBXXSHM\n";
71 $post_file = "#endif /* defined(HAVE_LIBXXSHM) */\n";
73 if($name eq "xpm") {
74 $pre_file = "#ifdef HAVE_LIBXXPM\n";
75 $post_file = "#endif /* defined(HAVE_LIBXXPM) */\n";
77 if($name eq "xf86vmode") {
78 $x11_incl = "#include <X11/Xlib.h>\n";
79 $extensions_dir = "extensions/";
80 $pre_file = "#include \"windef.h\"\n#ifdef HAVE_LIBXXF86VM\n#define XMD_H\n#include \"basetsd.h\"\n";
81 $post_file = "#endif /* defined(HAVE_LIBXXF86VM) */\n";
84 print OUTH <<END;
86 * Thread safe wrappers around $name calls.
87 * Always include this file instead of <X11/$name.h>.
88 * This file was generated automatically by tools/make_X11wrappers
90 * Copyright 1998 Kristian Nielsen
93 #ifndef __WINE_TS_$ucname\_H
94 #define __WINE_TS_$ucname\_H
96 #include "config.h"
98 #ifndef X_DISPLAY_MISSING
100 $pre_file
101 $x11_incl#include <X11/$extensions_dir$inc_name.h>
105 print OUTC <<END;
107 * Thread safe wrappers around $name calls.
108 * This file was generated automatically by tools/make_X11wrappers
109 * DO NOT EDIT!
112 #include "config.h"
114 #ifndef X_DISPLAY_MISSING
116 $pre_file
117 $x11_incl#include <X11/$extensions_dir$inc_name.h>
119 #include "debugtools.h"
120 #include "ts_$lcname.h"
121 #include "x11drv.h"
123 DEFAULT_DEBUG_CHANNEL(x11)
126 if($name eq "xpm") { # Handle as special case.
127 output_fn("XpmCreatePixmapFromData", "int",
128 "Display *, Drawable, char **, Pixmap *, Pixmap *, XpmAttributes *",
129 "Display *a0, Drawable a1, char **a2, Pixmap *a3, Pixmap *a4, XpmAttributes *a5",
130 "a0, a1, a2, a3, a4, a5");
131 output_fn("XpmAttributesSize", "int", "void", "void", "");
132 } elsif($name eq "XShm") {
133 output_fn("XShmQueryExtension", "Bool",
134 "Display *", "Display *a0", "a0");
135 output_fn("XShmQueryVersion", "Bool",
136 "Display *, int *, int *, Bool *",
137 "Display *a0, int *a1, int *a2, Bool *a3", "a0, a1, a2, a3");
138 output_fn("XShmPixmapFormat", "int",
139 "Display *", "Display *a0", "a0");
140 output_fn("XShmAttach", Status,
141 "Display *, XShmSegmentInfo *",
142 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
143 output_fn("XShmDetach", Status,
144 "Display *, XShmSegmentInfo *",
145 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
146 output_fn("XShmPutImage", Status,
147 "Display *, Drawable, GC, XImage *, int, int, int, int, unsigned int, unsigned int, Bool",
148 "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");
149 output_fn("XShmGetImage", Status,
150 "Display *, Drawable, XImage *, int, int, unsigned long",
151 "Display *a0, Drawable a1, XImage *a2, int a3, int a4, unsigned long a5",
152 "a0, a1, a2, a3, a4, a5");
153 output_fn("XShmCreateImage", "XImage *",
154 "Display *, Visual *, unsigned int, int, char *, XShmSegmentInfo *, unsigned int, unsigned int",
155 "Display *a0, Visual *a1, unsigned int a2, int a3, char *a4, XShmSegmentInfo *a5, unsigned int a6, unsigned int a7",
156 "a0, a1, a2, a3, a4, a5, a6, a7");
157 output_fn("XShmCreatePixmap", "Pixmap",
158 "Display *, Drawable, char *, XShmSegmentInfo *, unsigned int, unsigned int, unsigned int",
159 "Display *a0, Drawable a1, char *a2, XShmSegmentInfo *a3, unsigned int a4, unsigned int a5, unsigned int a6",
160 "a0, a1, a2, a3, a4, a5, a6");
161 } elsif($name eq "xf86dga") {
162 output_fn("XF86DGAQueryVersion",Bool,
163 "Display*,int*,int*",
164 "Display*a0,int*a1,int*a2",
165 "a0,a1,a2"
167 output_fn("XF86DGAQueryExtension",Bool,
168 "Display*,int*,int*",
169 "Display*a0,int*a1,int*a2",
170 "a0,a1,a2"
172 output_fn("XF86DGAGetVideo",Status,
173 "Display*,int,char**,int*,int*,int*",
174 "Display*a0,int a1,char**a2,int*a3,int*a4,int*a5",
175 "a0,a1,a2,a3,a4,a5"
177 output_fn("XF86DGADirectVideo",Status,
178 "Display*,int,int",
179 "Display*a0,int a1,int a2",
180 "a0,a1,a2"
182 output_fn("XF86DGAGetViewPortSize",Status,
183 "Display*,int,int*,int*",
184 "Display*a0,int a1,int *a2,int *a3",
185 "a0,a1,a2,a3"
187 output_fn("XF86DGASetViewPort",Status,
188 "Display*,int,int,int",
189 "Display*a0,int a1,int a2,int a3",
190 "a0,a1,a2,a3"
192 output_fn("XF86DGAInstallColormap",Status,
193 "Display*,int,Colormap",
194 "Display*a0,int a1,Colormap a2",
195 "a0,a1,a2"
197 output_fn("XF86DGAQueryDirectVideo",Status,
198 "Display*,int,int*",
199 "Display*a0,int a1,int *a2",
200 "a0,a1,a2"
202 output_fn("XF86DGAViewPortChanged",Status,
203 "Display*,int,int",
204 "Display*a0,int a1,int a2",
205 "a0,a1,a2"
207 } elsif($name eq "xf86dga2") {
208 output_fn_short("Bool", "XDGAQueryVersion", "Display*" ,"int*","int*");
209 output_fn_short("Bool", "XDGAQueryExtension", "Display*" ,"int*","int*");
210 output_fn_short("XDGAMode*", "XDGAQueryModes", "Display*" ,"int", "int*");
211 output_fn_short("XDGADevice*", "XDGASetMode", "Display*" ,"int","int");
212 output_fn_short("Bool", "XDGAOpenFramebuffer", "Display*" ,"int");
213 output_fn_short("void", "XDGACloseFramebuffer", "Display*" ,"int");
214 output_fn_short("void", "XDGASetViewport", "Display*" ,"int", "int", "int", "int");
215 output_fn_short("void", "XDGAInstallColormap", "Display*" , "int", "Colormap");
216 output_fn_short("Colormap", "XDGACreateColormap", "Display*" ,"int", "XDGADevice*", "int");
217 output_fn_short("void", "XDGASelectInput", "Display*" ,"int", "long");
218 output_fn_short("void", "XDGAFillRectangle", "Display*" ,"int", "int", "int", "unsigned int", "unsigned int", "unsigned long");
219 output_fn_short("void", "XDGACopyArea", "Display*" ,"int", "int", "int", "unsigned int", "unsigned int", "int", "int");
220 output_fn_short("void", "XDGACopyTransparentArea", "Display*" ,"int", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned long");
221 output_fn_short("int", "XDGAGetViewportStatus", "Display*" ,"int");
222 output_fn_short("void", "XDGASync", "Display*" ,"int");
223 output_fn_short("Bool", "XDGASetClientVersion", "Display*");
224 output_fn_short("void", "XDGAChangePixmapMode", "Display*" ,"int", "int*", "int*", "int");
225 output_fn_short("void", "XDGAKeyEventToXKeyEvent", "XDGAKeyEvent*" ,"XKeyEvent*");
226 } elsif($name eq "xf86vmode") {
227 output_fn("XF86VidModeQueryVersion",Bool,
228 "Display*,int*,int*",
229 "Display*a0,int*a1,int*a2",
230 "a0,a1,a2"
232 output_fn("XF86VidModeQueryExtension",Bool,
233 "Display*,int*,int*",
234 "Display*a0,int*a1,int*a2",
235 "a0,a2,a2"
237 output_fn("XF86VidModeGetModeLine",Bool,
238 "Display*,int,int*,XF86VidModeModeLine*",
239 "Display*a0,int a1,int*a2,XF86VidModeModeLine*a3",
240 "a0,a1,a2,a3"
242 output_fn("XF86VidModeGetAllModeLines",Bool,
243 "Display*,int,int*,XF86VidModeModeInfo***",
244 "Display*a0,int a1,int*a2,XF86VidModeModeInfo***a3",
245 "a0,a1,a2,a3"
247 output_fn("XF86VidModeAddModeLine",Bool,
248 "Display*,int,XF86VidModeModeInfo*,XF86VidModeModeInfo*",
249 "Display*a0,int a1,XF86VidModeModeInfo*a2,XF86VidModeModeInfo*a3",
250 "a0,a1,a2,a3"
252 output_fn("XF86VidModeDeleteModeLine",Bool,
253 "Display*,int,XF86VidModeModeInfo*",
254 "Display*a0,int a1,XF86VidModeModeInfo*a2",
255 "a0,a1,a2"
257 output_fn("XF86VidModeModModeLine",Bool,
258 "Display*,int,XF86VidModeModeLine*",
259 "Display*a0,int a1,XF86VidModeModeLine*a2",
260 "a0,a1,a2"
262 output_fn("XF86VidModeValidateModeLine",Status,
263 "Display*,int,XF86VidModeModeInfo*",
264 "Display*a0,int a1,XF86VidModeModeInfo*a2",
265 "a0,a1,a2"
267 output_fn("XF86VidModeSwitchMode",Bool,
268 "Display*,int,int",
269 "Display*a0,int a1,int a2",
270 "a0,a1,a2"
272 output_fn("XF86VidModeSwitchToMode",Bool,
273 "Display*,int,XF86VidModeModeInfo*",
274 "Display*a0,int a1,XF86VidModeModeInfo*a2",
275 "a0,a1,a2"
277 output_fn("XF86VidModeLockModeSwitch",Bool,
278 "Display*,int,int",
279 "Display*a0,int a1,int a2",
280 "a0,a1,a2"
282 output_fn("XF86VidModeGetMonitor",Bool,
283 "Display*,int,XF86VidModeMonitor*",
284 "Display*a0,int a1,XF86VidModeMonitor*a2",
285 "a0,a1,a2"
287 output_fn("XF86VidModeGetViewPort",Bool,
288 "Display*,int,int*,int*",
289 "Display*a0,int a1,int*a2,int*a3",
290 "a0,a1,a2,a3"
292 output_fn("XF86VidModeSetViewPort",Bool,
293 "Display*,int,int,int",
294 "Display*a0,int a1,int a2,int a3",
295 "a0,a1,a2,a3"
297 } else {
298 open(IN,
299 "echo \"$x11_incl#include <X11/$extensions_dir$name.h>\" | " .
300 "gcc -L$X11_include_dir -DNeedFunctionPrototypes -E - | " .
301 "grep -v '^[ \t]*\$)' |"
302 ) || die "open";
304 PROTO: while(<IN>) {
305 if(m'extern\s+([^()]*)\b([a-zA-Z0-9_]+)\s*\(') {
306 $result_type = $1;
307 $fn_name = $2;
308 $result_type = "int" if $result_type =~ /^\s*$/;
309 @args = ();
310 while(<IN>) {
311 last if m'\)\s*;';
312 # Give up on vararg functions and function pointer args.
313 if(m'\.\.\.|\(\*\)') {
314 undef $fn_name;
315 last;
317 if(m'\s*([^,]*[^, \t])\s*(,?\n)') {
318 $args[$#args+1] = $1;
319 if ($1 =~ /char\s*\[/) { # small hack for XQueryKeymap
320 $args[$#args] = "char*";
324 # Skip if vararg, function pointer arg, or not needed.
325 next unless $fn_name;
326 next unless $want{$fn_name} && $want{$fn_name} == 1;
328 # Special case for no arguments (which is specified as "void").
329 if($#args == 0 && $args[0] eq "void") {
330 @args = ();
332 $proto = "";
333 $formals = "";
334 $actuals = "";
335 for($i = 0; $i <= $#args; $i++) {
336 $comma = $i < $#args ? ", " : "";
337 $proto .= "$args[$i]$comma";
338 $formals .= "$args[$i] a$i$comma";
339 $actuals .= "a$i$comma";
341 $proto = $formals = "void" if $#args == -1;
342 output_fn($fn_name, $result_type, $proto, $formals, $actuals);
347 if($name eq "Xlib") {
348 raw_output_fn("XSynchronize", "int (*r)(Display *)",
349 "int (*TSXSynchronize(Display *, Bool))(Display *)",
350 "int (*TSXSynchronize(Display *a0, Bool a1))(Display *)",
351 "a0, a1");
352 print OUTC "\nextern void _XInitImageFuncPtrs(XImage *);\n";
353 output_fn("_XInitImageFuncPtrs", "void", "XImage *", "XImage *a0", "a0");
354 } elsif($name eq "Xutil") {
355 output_fn("XDestroyImage", "int",
356 "struct _XImage *", "struct _XImage *a0", "a0");
357 output_fn("XGetPixel", "unsigned long",
358 "struct _XImage *, int, int",
359 "struct _XImage *a0, int a1, int a2",
360 "a0, a1, a2");
361 output_fn("XPutPixel", "int",
362 "struct _XImage *, int, int, unsigned long",
363 "struct _XImage *a0, int a1, int a2, unsigned long a3",
364 "a0, a1, a2, a3");
365 output_fn("XSubImage", "struct _XImage *",
366 "struct _XImage *, int, int, unsigned int, unsigned int",
367 "struct _XImage *a0, int a1, int a2, unsigned int a3, unsigned int a4",
368 "a0, a1, a2, a3, a4");
369 output_fn("XAddPixel", "int",
370 "struct _XImage *, long",
371 "struct _XImage *a0, long a1", "a0, a1");
372 output_fn("XUniqueContext", "XContext", "void", "void", "");
375 print OUTH <<END;
377 $post_file
378 #endif /* !defined(X_DISPLAY_MISSING) */
380 #endif /* __WINE_TS_$ucname\_H */
382 print OUTC <<END;
384 $post_file
385 #endif /* !defined(X_DISPLAY_MISSING) */
392 foreach $i (keys %want) {
393 if($want{$i} == 1) {
394 print "Unresolved: $i\n";
399 sub output_fn {
400 # Example call:
401 # output_fn("main", "int", "int, char **", "int a0, char **a1", "a0, a1")
404 my ($fn_name, $result_type, $protos, $formals, $actuals) = @_;
406 return raw_output_fn($fn_name,
407 $result_type =~ /^\s*void\s*$/ ? "" : "$result_type r",
408 "$result_type TS$fn_name($protos)",
409 "$result_type TS$fn_name($formals)",
410 $actuals);
413 sub output_fn_short {
414 # Example call:
415 # output_fn_sort("Bool", "XDGAQueryExtension", "Display *", "int *", "int *");
417 my ($result_type, $fn_name, @args) = @_;
419 my ($i, $proto, $formals, $actuals) = (0,
420 "$result_type TS$fn_name(",
421 "$result_type TS$fn_name(",
422 "");
423 while ($val = shift @args) {
424 $proto = $proto . $val;
425 $formals = $formals . $val . " a$i";
426 $actuals = $actuals . " a$i";
427 $i++;
428 if (@args) {
429 $proto = $proto . ", ";
430 $formals = $formals . ", ";
431 $actuals = $actuals . ", ";
434 $proto = $proto . ")";
435 $formals = $formals . ")";
438 raw_output_fn($fn_name,
439 $result_type =~ /^\s*void\s*$/ ? "" : "$result_type r",
440 $proto,
441 $formals,
442 $actuals);
445 sub raw_output_fn {
446 # Example call:
447 # output_fn("main", "int r", "int main(int, char **)", "int main(int a0, char **a1)", "a0, a1")
450 my ($fn_name, $resultdecl, $protodecl, $defdecl, $actuals) = @_;
452 return undef unless $want{$fn_name} && $want{$fn_name} == 1;
454 print OUTC "\n$defdecl\n";
455 print OUTH "extern $protodecl;\n";
456 # print OUTH "#define $fn_name TS$fn_name\n";
457 print OUTC "{\n";
458 print OUTC " $resultdecl;\n" if $resultdecl;
459 print OUTC " TRACE(\"Call $fn_name\\n\");\n";
460 print OUTC " EnterCriticalSection( &X11DRV_CritSection );\n";
461 print OUTC " ";
462 print OUTC "r = " if $resultdecl;
463 print OUTC "$fn_name($actuals);\n";
464 print OUTC " LeaveCriticalSection( &X11DRV_CritSection );\n";
465 print OUTC " TRACE(\"Ret $fn_name\\n\");\n";
466 print OUTC " return r;\n" if $resultdecl;
467 print OUTC "}\n";
468 $want{$fn_name} = 2;
469 return 1;