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 = "#include \"config.h\"\n#ifdef HAVE_LIBXXF86DGA\n";
58 $post_file = "#endif";
61 $extensions_dir = "extensions/";
63 if($name eq "xf86vmode") {
64 $x11_incl = "#include <X11/Xlib.h>\n";
65 $extensions_dir = "extensions/";
66 $pre_file = "#include \"wintypes.h\"\n#ifdef HAVE_LIBXXF86VM\n#define XMD_H\n";
67 $post_file = "#endif";
72 * Thread safe wrappers around $name calls.
73 * Always include this file instead of <X11/$name.h>.
74 * This file was generated automatically by tools/make_X11wrappers
76 * Copyright 1998 Kristian Nielsen
79 #ifndef __WINE_TS$ucname\_H
80 #define __WINE_TS$ucname\_H
82 $x11_incl#include <X11/$extensions_dir$name.h>
88 * Thread safe wrappers around $name calls.
89 * This file was generated automatically by tools/make_X11wrappers
93 $x11_incl#include <X11/$extensions_dir$name.h>
98 if($name eq "xpm") { # Handle as special case.
99 output_fn
("XpmCreatePixmapFromData", "int",
100 "Display *, Drawable, char **, Pixmap *, Pixmap *, XpmAttributes *",
101 "Display *a0, Drawable a1, char **a2, Pixmap *a3, Pixmap *a4, XpmAttributes *a5",
102 "a0, a1, a2, a3, a4, a5");
103 output_fn
("XpmAttributesSize", "int", "void", "void", "");
104 } elsif($name eq "XShm") {
105 output_fn
("XShmQueryExtension", "Bool",
106 "Display *", "Display *a0", "a0");
107 output_fn
("XShmQueryVersion", "Bool",
108 "Display *, int *, int *, Bool *",
109 "Display *a0, int *a1, int *a2, Bool *a3", "a0, a1, a2, a3");
110 output_fn
("XShmPixmapFormat", "int",
111 "Display *", "Display *a0", "a0");
112 output_fn
("XShmAttach", Status
,
113 "Display *, XShmSegmentInfo *",
114 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
115 output_fn
("XShmDetach", Status
,
116 "Display *, XShmSegmentInfo *",
117 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
118 output_fn
("XShmPutImage", Status
,
119 "Display *, Drawable, GC, XImage *, int, int, int, int, unsigned int, unsigned int, Bool",
120 "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");
121 output_fn
("XShmGetImage", Status
,
122 "Display *, Drawable, XImage *, int, int, unsigned long",
123 "Display *a0, Drawable a1, XImage *a2, int a3, int a4, unsigned long a5",
124 "a0, a1, a2, a3, a4, a5");
125 output_fn
("XShmCreateImage", "XImage *",
126 "Display *, Visual *, unsigned int, int, char *, XShmSegmentInfo *, unsigned int, unsigned int",
127 "Display *a0, Visual *a1, unsigned int a2, int a3, char *a4, XShmSegmentInfo *a5, unsigned int a6, unsigned int a7",
128 "a0, a1, a2, a3, a4, a5, a6, a7");
129 output_fn
("XShmCreatePixmap", "Pixmap",
130 "Display *, Drawable, char *, XShmSegmentInfo *, unsigned int, unsigned int, unsigned int",
131 "Display *a0, Drawable a1, char *a2, XShmSegmentInfo *a3, unsigned int a4, unsigned int a5, unsigned int a6",
132 "a0, a1, a2, a3, a4, a5, a6");
133 } elsif($name eq "xf86dga") {
134 output_fn
("XF86DGAQueryVersion",Bool
,
135 "Display*,int*,int*",
136 "Display*a0,int*a1,int*a2",
139 output_fn
("XF86DGAQueryExtension",Bool
,
140 "Display*,int*,int*",
141 "Display*a0,int*a1,int*a2",
144 output_fn
("XF86DGAGetVideo",Status
,
145 "Display*,int,char**,int*,int*,int*",
146 "Display*a0,int a1,char**a2,int*a3,int*a4,int*a5",
149 output_fn
("XF86DGADirectVideo",Status
,
151 "Display*a0,int a1,int a2",
154 output_fn
("XF86DGAGetViewPortSize",Status
,
155 "Display*,int,int*,int*",
156 "Display*a0,int a1,int *a2,int *a3",
159 output_fn
("XF86DGASetViewPort",Status
,
160 "Display*,int,int,int",
161 "Display*a0,int a1,int a2,int a3",
164 output_fn
("XF86DGAInstallColormap",Status
,
165 "Display*,int,Colormap",
166 "Display*a0,int a1,Colormap a2",
169 output_fn
("XF86DGAQueryDirectVideo",Status
,
171 "Display*a0,int a1,int *a2",
174 output_fn
("XF86DGAViewPortChanged",Status
,
176 "Display*a0,int a1,int a2",
179 } elsif($name eq "xf86vmode") {
180 output_fn
("XF86VidModeQueryVersion",Bool
,
181 "Display*,int*,int*",
182 "Display*a0,int*a1,int*a2",
185 output_fn
("XF86VidModeQueryExtension",Bool
,
186 "Display*,int*,int*",
187 "Display*a0,int*a1,int*a2",
190 output_fn
("XF86VidModeGetModeLine",Bool
,
191 "Display*,int,int*,XF86VidModeModeLine*",
192 "Display*a0,int a1,int*a2,XF86VidModeModeLine*a3",
195 output_fn
("XF86VidModeGetAllModeLines",Bool
,
196 "Display*,int,int*,XF86VidModeModeInfo***",
197 "Display*a0,int a1,int*a2,XF86VidModeModeInfo***a3",
200 output_fn
("XF86VidModeAddModeLine",Bool
,
201 "Display*,int,XF86VidModeModeInfo*,XF86VidModeModeInfo*",
202 "Display*a0,int a1,XF86VidModeModeInfo*a2,XF86VidModeModeInfo*a3",
205 output_fn
("XF86VidModeDeleteModeLine",Bool
,
206 "Display*,int,XF86VidModeModeInfo*",
207 "Display*a0,int a1,XF86VidModeModeInfo*a2",
210 output_fn
("XF86VidModeModModeLine",Bool
,
211 "Display*,int,XF86VidModeModeLine*",
212 "Display*a0,int a1,XF86VidModeModeLine*a2",
215 output_fn
("XF86VidModeValidateModeLine",Status
,
216 "Display*,int,XF86VidModeModeInfo*",
217 "Display*a0,int a1,XF86VidModeModeInfo*a2",
220 output_fn
("XF86VidModeSwitchMode",Bool
,
222 "Display*a0,int a1,int a2",
225 output_fn
("XF86VidModeSwitchToMode",Bool
,
226 "Display*,int,XF86VidModeModeInfo*",
227 "Display*a0,int a1,XF86VidModeModeInfo*a2",
230 output_fn
("XF86VidModeLockModeSwitch",Bool
,
232 "Display*a0,int a1,int a2",
235 output_fn
("XF86VidModeGetMonitor",Bool
,
236 "Display*,int,XF86VidModeMonitor*",
237 "Display*a0,int a1,XF86VidModeMonitor*a2",
240 output_fn
("XF86VidModeGetViewPort",Bool
,
241 "Display*,int,int*,int*",
242 "Display*a0,int a1,int*a2,int*a3",
245 output_fn
("XF86VidModeSetViewPort",Bool
,
246 "Display*,int,int,int",
247 "Display*a0,int a1,int a2,int a3",
251 open(IN
, "echo \"$x11_incl#include <X11/$extensions_dir$name.h>\" | gcc -L$X11_include_dir -E - | grep -v '^[ \t]*\$'|") || die "open";
254 if(m
'extern\s+([^()]*)\b([a-zA-Z0-9_]+)\s*\(') {
257 $result_type = "int" if $result_type =~ /^\s*$/;
261 # Give up on vararg functions and function pointer args.
262 if(m
'\.\.\.|\(\*\)') {
266 if(m
'\s*([^,]*[^, \t])\s*(,?\n)') {
267 $args[$#args+1] = $1;
268 if ($1 =~ /char\s*\[/) { # small hack for XQueryKeymap
269 $args[$#args] = "char*";
273 # Skip if vararg, function pointer arg, or not needed.
274 next unless $fn_name;
275 next unless $want{$fn_name} && $want{$fn_name} == 1;
277 # Special case for no arguments (which is specified as "void").
278 if($#args == 0 && $args[0] eq "void") {
284 for($i = 0; $i <= $#args; $i++) {
285 $comma = $i < $#args ?
", " : "";
286 $proto .= "$args[$i]$comma";
287 $formals .= "$args[$i] a$i$comma";
288 $actuals .= "a$i$comma";
290 $proto = $formals = "void" if $#args == -1;
291 output_fn
($fn_name, $result_type, $proto, $formals, $actuals);
296 if($name eq "Xlib") {
297 raw_output_fn
("XSynchronize", "int (*r)(Display *)",
298 "int (*TSXSynchronize(Display *, Bool))(Display *)",
299 "int (*TSXSynchronize(Display *a0, Bool a1))(Display *)",
301 print OUTC
"\nextern void _XInitImageFuncPtrs(XImage *);\n";
302 output_fn
("_XInitImageFuncPtrs", "void", "XImage *", "XImage *a0", "a0");
303 } elsif($name eq "Xutil") {
304 output_fn
("XDestroyImage", "int",
305 "struct _XImage *", "struct _XImage *a0", "a0");
306 output_fn
("XGetPixel", "unsigned long",
307 "struct _XImage *, int, int",
308 "struct _XImage *a0, int a1, int a2",
310 output_fn
("XPutPixel", "int",
311 "struct _XImage *, int, int, unsigned long",
312 "struct _XImage *a0, int a1, int a2, unsigned long a3",
314 output_fn
("XSubImage", "struct _XImage *",
315 "struct _XImage *, int, int, unsigned int, unsigned int",
316 "struct _XImage *a0, int a1, int a2, unsigned int a3, unsigned int a4",
317 "a0, a1, a2, a3, a4");
318 output_fn
("XAddPixel", "int",
319 "struct _XImage *, long",
320 "struct _XImage *a0, long a1", "a0, a1");
321 output_fn
("XUniqueContext", "XContext", "void", "void", "");
326 #endif /* __WINE_TS$ucname\_H */
336 foreach $i (keys %want) {
338 print "Unresolved: $i\n";
345 # output_fn("main", "int", "int, char **", "int a0, char **a1", "a0, a1")
348 my ($fn_name, $result_type, $protos, $formals, $actuals) = @_;
350 return raw_output_fn
($fn_name,
351 $result_type =~ /^\s*void\s*$/ ?
"" : "$result_type r",
352 "$result_type TS$fn_name($protos)",
353 "$result_type TS$fn_name($formals)",
359 # output_fn("main", "int r", "int main(int, char **)", "int main(int a0, char **a1)", "a0, a1")
362 my ($fn_name, $resultdecl, $protodecl, $defdecl, $actuals) = @_;
364 return undef unless $want{$fn_name} && $want{$fn_name} == 1;
366 print OUTC
"\n$defdecl\n";
367 print OUTH
"extern $protodecl;\n";
368 # print OUTH "#define $fn_name TS$fn_name\n";
370 print OUTC
" $resultdecl;\n" if $resultdecl;
371 print OUTC
" TRACE(x11, \"Call $fn_name\\n\");\n";
372 print OUTC
" EnterCriticalSection( &X11DRV_CritSection );\n";
374 print OUTC
"r = " if $resultdecl;
375 print OUTC
"$fn_name($actuals);\n";
376 print OUTC
" LeaveCriticalSection( &X11DRV_CritSection );\n";
377 print OUTC
" TRACE(x11, \"Ret $fn_name\\n\");\n";
378 print OUTC
" return r;\n" if $resultdecl;