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");
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/";
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>
82 * Thread safe wrappers around $name calls.
83 * This file was generated automatically by tools/make_X11wrappers
87 $x11_incl#include <X11/$extensions_dir$name.h>
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",
118 output_fn
("XF86DGAQueryExtension",Bool
,
119 "Display*,int*,int*",
120 "Display*a0,int*a1,int*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",
128 output_fn
("XF86DGADirectVideo",Status
,
130 "Display*a0,int a1,int a2",
133 output_fn
("XF86DGAGetViewPortSize",Status
,
134 "Display*,int,int*,int*",
135 "Display*a0,int a1,int *a2,int *a3",
138 output_fn
("XF86DGASetViewPort",Status
,
139 "Display*,int,int,int",
140 "Display*a0,int a1,int a2,int a3",
143 output_fn
("XF86DGAInstallColormap",Status
,
144 "Display*,int,Colormap",
145 "Display*a0,int a1,Colormap a2",
148 output_fn
("XF86DGAQueryDirectVideo",Status
,
150 "Display*a0,int a1,int *a2",
153 output_fn
("XF86DGAViewPortChanged",Status
,
155 "Display*a0,int a1,int a2",
159 open(IN
, "echo \"$x11_incl#include <X11/$extensions_dir$name.h>\" | gcc -L$X11_include_dir -E - | grep -v '^[ \t]*\$'|") || die "open";
162 if(m
'extern\s+([^()]*)\b([a-zA-Z0-9_]+)\s*\(') {
165 $result_type = "int" if $result_type =~ /^\s*$/;
169 # Give up on vararg functions and function pointer args.
170 if(m
'\.\.\.|\(\*\)') {
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") {
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 *)",
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",
215 output_fn
("XPutPixel", "int",
216 "struct _XImage *, int, int, unsigned long",
217 "struct _XImage *a0, int a1, int a2, unsigned long 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", "");
231 #endif /* __WINE_TS$ucname\_H */
241 foreach $i (keys %want) {
243 print "Unresolved: $i\n";
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)",
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";
275 print OUTC
" $resultdecl;\n" if $resultdecl;
276 print OUTC
" TRACE(x11, \"Call $fn_name\\n\");\n";
277 print OUTC
" EnterCriticalSection( &X11DRV_CritSection );\n";
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;