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";
19 $wantfile = "$outdir/X11_calls";
20 @dolist = ("Xlib", "Xresource", "Xutil", "xpm", "XShm", "xf86dga", "xf86vmode");
22 # First read list of wanted function names.
24 open(WANT
, $wantfile) || die "open";
26 next if /^\s*\#/; # Skip comment lines.
27 next if /^\s*$/; # Skip empty lines.
28 if(/^\s*([a-zA-Z0-9_]+)\s*$/) {
31 die "syntax error in file '$wantfile', in line '$_'";
36 foreach $name (@dolist) {
41 $outfile = "/ts_$lcname";
42 open(OUTC
, ">$outdir/$outfile.c") || die "open";
43 open(OUTH
, ">include/$outfile.h") || die "open";
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 = "#ifdef HAVE_LIBXXF86DGA\n";
58 $post_file = "#endif /* defined(HAVE_LIBXXF86DGA) */\n";
61 $extensions_dir = "extensions/";
62 $pre_file = "#ifdef HAVE_LIBXXSHM\n";
63 $post_file = "#endif /* defined(HAVE_LIBXXSHM) */\n";
66 $pre_file = "#ifdef HAVE_LIBXXPM\n";
67 $post_file = "#endif /* defined(HAVE_LIBXXPM) */\n";
69 if($name eq "xf86vmode") {
70 $x11_incl = "#include <X11/Xlib.h>\n";
71 $extensions_dir = "extensions/";
72 $pre_file = "#include \"windef.h\"\n#ifdef HAVE_LIBXXF86VM\n#define XMD_H\n#define INT32 INT\n";
73 $post_file = "#endif /* defined(HAVE_LIBXXF86VM) */\n";
78 * Thread safe wrappers around $name calls.
79 * Always include this file instead of <X11/$name.h>.
80 * This file was generated automatically by tools/make_X11wrappers
82 * Copyright 1998 Kristian Nielsen
85 #ifndef __WINE_TS$ucname\_H
86 #define __WINE_TS$ucname\_H
90 #ifndef X_DISPLAY_MISSING
93 $x11_incl#include <X11/$extensions_dir$name.h>
99 * Thread safe wrappers around $name calls.
100 * This file was generated automatically by tools/make_X11wrappers
106 #ifndef X_DISPLAY_MISSING
109 $x11_incl#include <X11/$extensions_dir$name.h>
113 DEFAULT_DEBUG_CHANNEL(x11)
116 if($name eq "xpm") { # Handle as special case.
117 output_fn
("XpmCreatePixmapFromData", "int",
118 "Display *, Drawable, char **, Pixmap *, Pixmap *, XpmAttributes *",
119 "Display *a0, Drawable a1, char **a2, Pixmap *a3, Pixmap *a4, XpmAttributes *a5",
120 "a0, a1, a2, a3, a4, a5");
121 output_fn
("XpmAttributesSize", "int", "void", "void", "");
122 } elsif($name eq "XShm") {
123 output_fn
("XShmQueryExtension", "Bool",
124 "Display *", "Display *a0", "a0");
125 output_fn
("XShmQueryVersion", "Bool",
126 "Display *, int *, int *, Bool *",
127 "Display *a0, int *a1, int *a2, Bool *a3", "a0, a1, a2, a3");
128 output_fn
("XShmPixmapFormat", "int",
129 "Display *", "Display *a0", "a0");
130 output_fn
("XShmAttach", Status
,
131 "Display *, XShmSegmentInfo *",
132 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
133 output_fn
("XShmDetach", Status
,
134 "Display *, XShmSegmentInfo *",
135 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
136 output_fn
("XShmPutImage", Status
,
137 "Display *, Drawable, GC, XImage *, int, int, int, int, unsigned int, unsigned int, Bool",
138 "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");
139 output_fn
("XShmGetImage", Status
,
140 "Display *, Drawable, XImage *, int, int, unsigned long",
141 "Display *a0, Drawable a1, XImage *a2, int a3, int a4, unsigned long a5",
142 "a0, a1, a2, a3, a4, a5");
143 output_fn
("XShmCreateImage", "XImage *",
144 "Display *, Visual *, unsigned int, int, char *, XShmSegmentInfo *, unsigned int, unsigned int",
145 "Display *a0, Visual *a1, unsigned int a2, int a3, char *a4, XShmSegmentInfo *a5, unsigned int a6, unsigned int a7",
146 "a0, a1, a2, a3, a4, a5, a6, a7");
147 output_fn
("XShmCreatePixmap", "Pixmap",
148 "Display *, Drawable, char *, XShmSegmentInfo *, unsigned int, unsigned int, unsigned int",
149 "Display *a0, Drawable a1, char *a2, XShmSegmentInfo *a3, unsigned int a4, unsigned int a5, unsigned int a6",
150 "a0, a1, a2, a3, a4, a5, a6");
151 } elsif($name eq "xf86dga") {
152 output_fn
("XF86DGAQueryVersion",Bool
,
153 "Display*,int*,int*",
154 "Display*a0,int*a1,int*a2",
157 output_fn
("XF86DGAQueryExtension",Bool
,
158 "Display*,int*,int*",
159 "Display*a0,int*a1,int*a2",
162 output_fn
("XF86DGAGetVideo",Status
,
163 "Display*,int,char**,int*,int*,int*",
164 "Display*a0,int a1,char**a2,int*a3,int*a4,int*a5",
167 output_fn
("XF86DGADirectVideo",Status
,
169 "Display*a0,int a1,int a2",
172 output_fn
("XF86DGAGetViewPortSize",Status
,
173 "Display*,int,int*,int*",
174 "Display*a0,int a1,int *a2,int *a3",
177 output_fn
("XF86DGASetViewPort",Status
,
178 "Display*,int,int,int",
179 "Display*a0,int a1,int a2,int a3",
182 output_fn
("XF86DGAInstallColormap",Status
,
183 "Display*,int,Colormap",
184 "Display*a0,int a1,Colormap a2",
187 output_fn
("XF86DGAQueryDirectVideo",Status
,
189 "Display*a0,int a1,int *a2",
192 output_fn
("XF86DGAViewPortChanged",Status
,
194 "Display*a0,int a1,int a2",
197 } elsif($name eq "xf86vmode") {
198 output_fn
("XF86VidModeQueryVersion",Bool
,
199 "Display*,int*,int*",
200 "Display*a0,int*a1,int*a2",
203 output_fn
("XF86VidModeQueryExtension",Bool
,
204 "Display*,int*,int*",
205 "Display*a0,int*a1,int*a2",
208 output_fn
("XF86VidModeGetModeLine",Bool
,
209 "Display*,int,int*,XF86VidModeModeLine*",
210 "Display*a0,int a1,int*a2,XF86VidModeModeLine*a3",
213 output_fn
("XF86VidModeGetAllModeLines",Bool
,
214 "Display*,int,int*,XF86VidModeModeInfo***",
215 "Display*a0,int a1,int*a2,XF86VidModeModeInfo***a3",
218 output_fn
("XF86VidModeAddModeLine",Bool
,
219 "Display*,int,XF86VidModeModeInfo*,XF86VidModeModeInfo*",
220 "Display*a0,int a1,XF86VidModeModeInfo*a2,XF86VidModeModeInfo*a3",
223 output_fn
("XF86VidModeDeleteModeLine",Bool
,
224 "Display*,int,XF86VidModeModeInfo*",
225 "Display*a0,int a1,XF86VidModeModeInfo*a2",
228 output_fn
("XF86VidModeModModeLine",Bool
,
229 "Display*,int,XF86VidModeModeLine*",
230 "Display*a0,int a1,XF86VidModeModeLine*a2",
233 output_fn
("XF86VidModeValidateModeLine",Status
,
234 "Display*,int,XF86VidModeModeInfo*",
235 "Display*a0,int a1,XF86VidModeModeInfo*a2",
238 output_fn
("XF86VidModeSwitchMode",Bool
,
240 "Display*a0,int a1,int a2",
243 output_fn
("XF86VidModeSwitchToMode",Bool
,
244 "Display*,int,XF86VidModeModeInfo*",
245 "Display*a0,int a1,XF86VidModeModeInfo*a2",
248 output_fn
("XF86VidModeLockModeSwitch",Bool
,
250 "Display*a0,int a1,int a2",
253 output_fn
("XF86VidModeGetMonitor",Bool
,
254 "Display*,int,XF86VidModeMonitor*",
255 "Display*a0,int a1,XF86VidModeMonitor*a2",
258 output_fn
("XF86VidModeGetViewPort",Bool
,
259 "Display*,int,int*,int*",
260 "Display*a0,int a1,int*a2,int*a3",
263 output_fn
("XF86VidModeSetViewPort",Bool
,
264 "Display*,int,int,int",
265 "Display*a0,int a1,int a2,int a3",
269 open(IN
, "echo \"$x11_incl#include <X11/$extensions_dir$name.h>\" | gcc -L$X11_include_dir -E - | grep -v '^[ \t]*\$'|") || die "open";
272 if(m
'extern\s+([^()]*)\b([a-zA-Z0-9_]+)\s*\(') {
275 $result_type = "int" if $result_type =~ /^\s*$/;
279 # Give up on vararg functions and function pointer args.
280 if(m
'\.\.\.|\(\*\)') {
284 if(m
'\s*([^,]*[^, \t])\s*(,?\n)') {
285 $args[$#args+1] = $1;
286 if ($1 =~ /char\s*\[/) { # small hack for XQueryKeymap
287 $args[$#args] = "char*";
291 # Skip if vararg, function pointer arg, or not needed.
292 next unless $fn_name;
293 next unless $want{$fn_name} && $want{$fn_name} == 1;
295 # Special case for no arguments (which is specified as "void").
296 if($#args == 0 && $args[0] eq "void") {
302 for($i = 0; $i <= $#args; $i++) {
303 $comma = $i < $#args ?
", " : "";
304 $proto .= "$args[$i]$comma";
305 $formals .= "$args[$i] a$i$comma";
306 $actuals .= "a$i$comma";
308 $proto = $formals = "void" if $#args == -1;
309 output_fn
($fn_name, $result_type, $proto, $formals, $actuals);
314 if($name eq "Xlib") {
315 raw_output_fn
("XSynchronize", "int (*r)(Display *)",
316 "int (*TSXSynchronize(Display *, Bool))(Display *)",
317 "int (*TSXSynchronize(Display *a0, Bool a1))(Display *)",
319 print OUTC
"\nextern void _XInitImageFuncPtrs(XImage *);\n";
320 output_fn
("_XInitImageFuncPtrs", "void", "XImage *", "XImage *a0", "a0");
321 } elsif($name eq "Xutil") {
322 output_fn
("XDestroyImage", "int",
323 "struct _XImage *", "struct _XImage *a0", "a0");
324 output_fn
("XGetPixel", "unsigned long",
325 "struct _XImage *, int, int",
326 "struct _XImage *a0, int a1, int a2",
328 output_fn
("XPutPixel", "int",
329 "struct _XImage *, int, int, unsigned long",
330 "struct _XImage *a0, int a1, int a2, unsigned long a3",
332 output_fn
("XSubImage", "struct _XImage *",
333 "struct _XImage *, int, int, unsigned int, unsigned int",
334 "struct _XImage *a0, int a1, int a2, unsigned int a3, unsigned int a4",
335 "a0, a1, a2, a3, a4");
336 output_fn
("XAddPixel", "int",
337 "struct _XImage *, long",
338 "struct _XImage *a0, long a1", "a0, a1");
339 output_fn
("XUniqueContext", "XContext", "void", "void", "");
345 #endif /* !defined(X_DISPLAY_MISSING) */
347 #endif /* __WINE_TS$ucname\_H */
352 #endif /* !defined(X_DISPLAY_MISSING) */
359 foreach $i (keys %want) {
361 print "Unresolved: $i\n";
368 # output_fn("main", "int", "int, char **", "int a0, char **a1", "a0, a1")
371 my ($fn_name, $result_type, $protos, $formals, $actuals) = @_;
373 return raw_output_fn
($fn_name,
374 $result_type =~ /^\s*void\s*$/ ?
"" : "$result_type r",
375 "$result_type TS$fn_name($protos)",
376 "$result_type TS$fn_name($formals)",
382 # output_fn("main", "int r", "int main(int, char **)", "int main(int a0, char **a1)", "a0, a1")
385 my ($fn_name, $resultdecl, $protodecl, $defdecl, $actuals) = @_;
387 return undef unless $want{$fn_name} && $want{$fn_name} == 1;
389 print OUTC
"\n$defdecl\n";
390 print OUTH
"extern $protodecl;\n";
391 # print OUTH "#define $fn_name TS$fn_name\n";
393 print OUTC
" $resultdecl;\n" if $resultdecl;
394 print OUTC
" TRACE(x11, \"Call $fn_name\\n\");\n";
395 print OUTC
" EnterCriticalSection( &X11DRV_CritSection );\n";
397 print OUTC
"r = " if $resultdecl;
398 print OUTC
"$fn_name($actuals);\n";
399 print OUTC
" LeaveCriticalSection( &X11DRV_CritSection );\n";
400 print OUTC
" TRACE(x11, \"Ret $fn_name\\n\");\n";
401 print OUTC
" return r;\n" if $resultdecl;