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>
114 if($name eq "xpm") { # Handle as special case.
115 output_fn
("XpmCreatePixmapFromData", "int",
116 "Display *, Drawable, char **, Pixmap *, Pixmap *, XpmAttributes *",
117 "Display *a0, Drawable a1, char **a2, Pixmap *a3, Pixmap *a4, XpmAttributes *a5",
118 "a0, a1, a2, a3, a4, a5");
119 output_fn
("XpmAttributesSize", "int", "void", "void", "");
120 } elsif($name eq "XShm") {
121 output_fn
("XShmQueryExtension", "Bool",
122 "Display *", "Display *a0", "a0");
123 output_fn
("XShmQueryVersion", "Bool",
124 "Display *, int *, int *, Bool *",
125 "Display *a0, int *a1, int *a2, Bool *a3", "a0, a1, a2, a3");
126 output_fn
("XShmPixmapFormat", "int",
127 "Display *", "Display *a0", "a0");
128 output_fn
("XShmAttach", Status
,
129 "Display *, XShmSegmentInfo *",
130 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
131 output_fn
("XShmDetach", Status
,
132 "Display *, XShmSegmentInfo *",
133 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
134 output_fn
("XShmPutImage", Status
,
135 "Display *, Drawable, GC, XImage *, int, int, int, int, unsigned int, unsigned int, Bool",
136 "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");
137 output_fn
("XShmGetImage", Status
,
138 "Display *, Drawable, XImage *, int, int, unsigned long",
139 "Display *a0, Drawable a1, XImage *a2, int a3, int a4, unsigned long a5",
140 "a0, a1, a2, a3, a4, a5");
141 output_fn
("XShmCreateImage", "XImage *",
142 "Display *, Visual *, unsigned int, int, char *, XShmSegmentInfo *, unsigned int, unsigned int",
143 "Display *a0, Visual *a1, unsigned int a2, int a3, char *a4, XShmSegmentInfo *a5, unsigned int a6, unsigned int a7",
144 "a0, a1, a2, a3, a4, a5, a6, a7");
145 output_fn
("XShmCreatePixmap", "Pixmap",
146 "Display *, Drawable, char *, XShmSegmentInfo *, unsigned int, unsigned int, unsigned int",
147 "Display *a0, Drawable a1, char *a2, XShmSegmentInfo *a3, unsigned int a4, unsigned int a5, unsigned int a6",
148 "a0, a1, a2, a3, a4, a5, a6");
149 } elsif($name eq "xf86dga") {
150 output_fn
("XF86DGAQueryVersion",Bool
,
151 "Display*,int*,int*",
152 "Display*a0,int*a1,int*a2",
155 output_fn
("XF86DGAQueryExtension",Bool
,
156 "Display*,int*,int*",
157 "Display*a0,int*a1,int*a2",
160 output_fn
("XF86DGAGetVideo",Status
,
161 "Display*,int,char**,int*,int*,int*",
162 "Display*a0,int a1,char**a2,int*a3,int*a4,int*a5",
165 output_fn
("XF86DGADirectVideo",Status
,
167 "Display*a0,int a1,int a2",
170 output_fn
("XF86DGAGetViewPortSize",Status
,
171 "Display*,int,int*,int*",
172 "Display*a0,int a1,int *a2,int *a3",
175 output_fn
("XF86DGASetViewPort",Status
,
176 "Display*,int,int,int",
177 "Display*a0,int a1,int a2,int a3",
180 output_fn
("XF86DGAInstallColormap",Status
,
181 "Display*,int,Colormap",
182 "Display*a0,int a1,Colormap a2",
185 output_fn
("XF86DGAQueryDirectVideo",Status
,
187 "Display*a0,int a1,int *a2",
190 output_fn
("XF86DGAViewPortChanged",Status
,
192 "Display*a0,int a1,int a2",
195 } elsif($name eq "xf86vmode") {
196 output_fn
("XF86VidModeQueryVersion",Bool
,
197 "Display*,int*,int*",
198 "Display*a0,int*a1,int*a2",
201 output_fn
("XF86VidModeQueryExtension",Bool
,
202 "Display*,int*,int*",
203 "Display*a0,int*a1,int*a2",
206 output_fn
("XF86VidModeGetModeLine",Bool
,
207 "Display*,int,int*,XF86VidModeModeLine*",
208 "Display*a0,int a1,int*a2,XF86VidModeModeLine*a3",
211 output_fn
("XF86VidModeGetAllModeLines",Bool
,
212 "Display*,int,int*,XF86VidModeModeInfo***",
213 "Display*a0,int a1,int*a2,XF86VidModeModeInfo***a3",
216 output_fn
("XF86VidModeAddModeLine",Bool
,
217 "Display*,int,XF86VidModeModeInfo*,XF86VidModeModeInfo*",
218 "Display*a0,int a1,XF86VidModeModeInfo*a2,XF86VidModeModeInfo*a3",
221 output_fn
("XF86VidModeDeleteModeLine",Bool
,
222 "Display*,int,XF86VidModeModeInfo*",
223 "Display*a0,int a1,XF86VidModeModeInfo*a2",
226 output_fn
("XF86VidModeModModeLine",Bool
,
227 "Display*,int,XF86VidModeModeLine*",
228 "Display*a0,int a1,XF86VidModeModeLine*a2",
231 output_fn
("XF86VidModeValidateModeLine",Status
,
232 "Display*,int,XF86VidModeModeInfo*",
233 "Display*a0,int a1,XF86VidModeModeInfo*a2",
236 output_fn
("XF86VidModeSwitchMode",Bool
,
238 "Display*a0,int a1,int a2",
241 output_fn
("XF86VidModeSwitchToMode",Bool
,
242 "Display*,int,XF86VidModeModeInfo*",
243 "Display*a0,int a1,XF86VidModeModeInfo*a2",
246 output_fn
("XF86VidModeLockModeSwitch",Bool
,
248 "Display*a0,int a1,int a2",
251 output_fn
("XF86VidModeGetMonitor",Bool
,
252 "Display*,int,XF86VidModeMonitor*",
253 "Display*a0,int a1,XF86VidModeMonitor*a2",
256 output_fn
("XF86VidModeGetViewPort",Bool
,
257 "Display*,int,int*,int*",
258 "Display*a0,int a1,int*a2,int*a3",
261 output_fn
("XF86VidModeSetViewPort",Bool
,
262 "Display*,int,int,int",
263 "Display*a0,int a1,int a2,int a3",
267 open(IN
, "echo \"$x11_incl#include <X11/$extensions_dir$name.h>\" | gcc -L$X11_include_dir -E - | grep -v '^[ \t]*\$'|") || die "open";
270 if(m
'extern\s+([^()]*)\b([a-zA-Z0-9_]+)\s*\(') {
273 $result_type = "int" if $result_type =~ /^\s*$/;
277 # Give up on vararg functions and function pointer args.
278 if(m
'\.\.\.|\(\*\)') {
282 if(m
'\s*([^,]*[^, \t])\s*(,?\n)') {
283 $args[$#args+1] = $1;
284 if ($1 =~ /char\s*\[/) { # small hack for XQueryKeymap
285 $args[$#args] = "char*";
289 # Skip if vararg, function pointer arg, or not needed.
290 next unless $fn_name;
291 next unless $want{$fn_name} && $want{$fn_name} == 1;
293 # Special case for no arguments (which is specified as "void").
294 if($#args == 0 && $args[0] eq "void") {
300 for($i = 0; $i <= $#args; $i++) {
301 $comma = $i < $#args ?
", " : "";
302 $proto .= "$args[$i]$comma";
303 $formals .= "$args[$i] a$i$comma";
304 $actuals .= "a$i$comma";
306 $proto = $formals = "void" if $#args == -1;
307 output_fn
($fn_name, $result_type, $proto, $formals, $actuals);
312 if($name eq "Xlib") {
313 raw_output_fn
("XSynchronize", "int (*r)(Display *)",
314 "int (*TSXSynchronize(Display *, Bool))(Display *)",
315 "int (*TSXSynchronize(Display *a0, Bool a1))(Display *)",
317 print OUTC
"\nextern void _XInitImageFuncPtrs(XImage *);\n";
318 output_fn
("_XInitImageFuncPtrs", "void", "XImage *", "XImage *a0", "a0");
319 } elsif($name eq "Xutil") {
320 output_fn
("XDestroyImage", "int",
321 "struct _XImage *", "struct _XImage *a0", "a0");
322 output_fn
("XGetPixel", "unsigned long",
323 "struct _XImage *, int, int",
324 "struct _XImage *a0, int a1, int a2",
326 output_fn
("XPutPixel", "int",
327 "struct _XImage *, int, int, unsigned long",
328 "struct _XImage *a0, int a1, int a2, unsigned long a3",
330 output_fn
("XSubImage", "struct _XImage *",
331 "struct _XImage *, int, int, unsigned int, unsigned int",
332 "struct _XImage *a0, int a1, int a2, unsigned int a3, unsigned int a4",
333 "a0, a1, a2, a3, a4");
334 output_fn
("XAddPixel", "int",
335 "struct _XImage *, long",
336 "struct _XImage *a0, long a1", "a0, a1");
337 output_fn
("XUniqueContext", "XContext", "void", "void", "");
343 #endif /* !defined(X_DISPLAY_MISSING) */
345 #endif /* __WINE_TS$ucname\_H */
350 #endif /* !defined(X_DISPLAY_MISSING) */
357 foreach $i (keys %want) {
359 print "Unresolved: $i\n";
366 # output_fn("main", "int", "int, char **", "int a0, char **a1", "a0, a1")
369 my ($fn_name, $result_type, $protos, $formals, $actuals) = @_;
371 return raw_output_fn
($fn_name,
372 $result_type =~ /^\s*void\s*$/ ?
"" : "$result_type r",
373 "$result_type TS$fn_name($protos)",
374 "$result_type TS$fn_name($formals)",
380 # output_fn("main", "int r", "int main(int, char **)", "int main(int a0, char **a1)", "a0, a1")
383 my ($fn_name, $resultdecl, $protodecl, $defdecl, $actuals) = @_;
385 return undef unless $want{$fn_name} && $want{$fn_name} == 1;
387 print OUTC
"\n$defdecl\n";
388 print OUTH
"extern $protodecl;\n";
389 # print OUTH "#define $fn_name TS$fn_name\n";
391 print OUTC
" $resultdecl;\n" if $resultdecl;
392 print OUTC
" TRACE(x11, \"Call $fn_name\\n\");\n";
393 print OUTC
" EnterCriticalSection( &X11DRV_CritSection );\n";
395 print OUTC
"r = " if $resultdecl;
396 print OUTC
"$fn_name($actuals);\n";
397 print OUTC
" LeaveCriticalSection( &X11DRV_CritSection );\n";
398 print OUTC
" TRACE(x11, \"Ret $fn_name\\n\");\n";
399 print OUTC
" return r;\n" if $resultdecl;