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;
176 if ($1 =~ /char\s*\[/) { # small hack for XQueryKeymap
177 $args[$#args] = "char*";
181 # Skip if vararg, function pointer arg, or not needed.
182 next unless $fn_name;
183 next unless $want{$fn_name} && $want{$fn_name} == 1;
185 # Special case for no arguments (which is specified as "void").
186 if($#args == 0 && $args[0] eq "void") {
192 for($i = 0; $i <= $#args; $i++) {
193 $comma = $i < $#args ?
", " : "";
194 $proto .= "$args[$i]$comma";
195 $formals .= "$args[$i] a$i$comma";
196 $actuals .= "a$i$comma";
198 $proto = $formals = "void" if $#args == -1;
199 output_fn
($fn_name, $result_type, $proto, $formals, $actuals);
204 if($name eq "Xlib") {
205 raw_output_fn
("XSynchronize", "int (*r)(Display *)",
206 "int (*TSXSynchronize(Display *, Bool))(Display *)",
207 "int (*TSXSynchronize(Display *a0, Bool a1))(Display *)",
209 print OUTC
"\nextern void _XInitImageFuncPtrs(XImage *);\n";
210 output_fn
("_XInitImageFuncPtrs", "void", "XImage *", "XImage *a0", "a0");
211 } elsif($name eq "Xutil") {
212 output_fn
("XDestroyImage", "int",
213 "struct _XImage *", "struct _XImage *a0", "a0");
214 output_fn
("XGetPixel", "unsigned long",
215 "struct _XImage *, int, int",
216 "struct _XImage *a0, int a1, int a2",
218 output_fn
("XPutPixel", "int",
219 "struct _XImage *, int, int, unsigned long",
220 "struct _XImage *a0, int a1, int a2, unsigned long a3",
222 output_fn
("XSubImage", "struct _XImage *",
223 "struct _XImage *, int, int, unsigned int, unsigned int",
224 "struct _XImage *a0, int a1, int a2, unsigned int a3, unsigned int a4",
225 "a0, a1, a2, a3, a4");
226 output_fn
("XAddPixel", "int",
227 "struct _XImage *, long",
228 "struct _XImage *a0, long a1", "a0, a1");
229 output_fn
("XUniqueContext", "XContext", "void", "void", "");
234 #endif /* __WINE_TS$ucname\_H */
244 foreach $i (keys %want) {
246 print "Unresolved: $i\n";
253 # output_fn("main", "int", "int, char **", "int a0, char **a1", "a0, a1")
256 my ($fn_name, $result_type, $protos, $formals, $actuals) = @_;
258 return raw_output_fn
($fn_name,
259 $result_type =~ /^\s*void\s*$/ ?
"" : "$result_type r",
260 "$result_type TS$fn_name($protos)",
261 "$result_type TS$fn_name($formals)",
267 # output_fn("main", "int r", "int main(int, char **)", "int main(int a0, char **a1)", "a0, a1")
270 my ($fn_name, $resultdecl, $protodecl, $defdecl, $actuals) = @_;
272 return undef unless $want{$fn_name} && $want{$fn_name} == 1;
274 print OUTC
"\n$defdecl\n";
275 print OUTH
"extern $protodecl;\n";
276 # print OUTH "#define $fn_name TS$fn_name\n";
278 print OUTC
" $resultdecl;\n" if $resultdecl;
279 print OUTC
" TRACE(x11, \"Call $fn_name\\n\");\n";
280 print OUTC
" EnterCriticalSection( &X11DRV_CritSection );\n";
282 print OUTC
"r = " if $resultdecl;
283 print OUTC
"$fn_name($actuals);\n";
284 print OUTC
" LeaveCriticalSection( &X11DRV_CritSection );\n";
285 print OUTC
" TRACE(x11, \"Ret $fn_name\\n\");\n";
286 print OUTC
" return r;\n" if $resultdecl;