Superflous WINAPI removed.
[wine/multimedia.git] / tools / make_X11wrappers
blobb074e3caee0ffebc9299ca6ceea6553637eb3d39
1 #!/usr/bin/perl -w
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";
18 $outdir = "tsx11";
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";
25 while(<WANT>) {
26 next if /^\s*\#/; # Skip comment lines.
27 next if /^\s*$/; # Skip empty lines.
28 if(/^\s*([a-zA-Z0-9_]+)\s*$/) {
29 $want{$1} = 1;
30 } else {
31 die "syntax error in file '$wantfile', in line '$_'";
34 close(WANT);
36 foreach $name (@dolist) {
38 $ucname = uc $name;
39 $lcname = lc $name;
41 $outfile = "/ts_$lcname";
42 open(OUTC, ">$outdir/$outfile.c") || die "open";
43 open(OUTH, ">include/$outfile.h") || die "open";
45 $x11_incl = "";
46 $extensions_dir = "";
47 $pre_file = "";
48 $post_file = "";
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";
60 if($name eq "XShm") {
61 $extensions_dir = "extensions/";
64 print OUTH <<END;
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>
78 END
80 print OUTC <<END;
82 * Thread safe wrappers around $name calls.
83 * This file was generated automatically by tools/make_X11wrappers
84 * DO NOT EDIT!
86 $pre_file
87 $x11_incl#include <X11/$extensions_dir$name.h>
88 #include "x11drv.h"
89 #include "debug.h"
90 END
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("XShmQueryVersion", "Bool",
102 "Display *, int *, int *, Bool *",
103 "Display *a0, int *a1, int *a2, Bool *a3", "a0, a1, a2, a3");
104 output_fn("XShmPixmapFormat", "int",
105 "Display *", "Display *a0", "a0");
106 output_fn("XShmAttach", Status,
107 "Display *, XShmSegmentInfo *",
108 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
109 output_fn("XShmDetach", Status,
110 "Display *, XShmSegmentInfo *",
111 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
112 output_fn("XShmPutImage", Status,
113 "Display *, Drawable, GC, XImage *, int, int, int, int, unsigned int, unsigned int, Bool",
114 "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");
115 output_fn("XShmGetImage", Status,
116 "Display *, Drawable, XImage *, int, int, unsigned long",
117 "Display *a0, Drawable a1, XImage *a2, int a3, int a4, unsigned long a5",
118 "a0, a1, a2, a3, a4, a5");
119 output_fn("XShmCreateImage", "XImage *",
120 "Display *, Visual *, unsigned int, int, char *, XShmSegmentInfo *, unsigned int, unsigned int",
121 "Display *a0, Visual *a1, unsigned int a2, int a3, char *a4, XShmSegmentInfo *a5, unsigned int a6, unsigned int a7",
122 "a0, a1, a2, a3, a4, a5, a6, a7");
123 output_fn("XShmCreatePixmap", "Pixmap",
124 "Display *, Drawable, char *, XShmSegmentInfo *, unsigned int, unsigned int, unsigned int",
125 "Display *a0, Drawable a1, char *a2, XShmSegmentInfo *a3, unsigned int a4, unsigned int a5, unsigned int a6",
126 "a0, a1, a2, a3, a4, a5, a6");
127 } elsif($name eq "xf86dga") {
128 output_fn("XF86DGAQueryVersion",Bool,
129 "Display*,int*,int*",
130 "Display*a0,int*a1,int*a2",
131 "a0,a1,a2"
133 output_fn("XF86DGAQueryExtension",Bool,
134 "Display*,int*,int*",
135 "Display*a0,int*a1,int*a2",
136 "a0,a1,a2"
138 output_fn("XF86DGAGetVideo",Status,
139 "Display*,int,char**,int*,int*,int*",
140 "Display*a0,int a1,char**a2,int*a3,int*a4,int*a5",
141 "a0,a1,a2,a3,a4,a5"
143 output_fn("XF86DGADirectVideo",Status,
144 "Display*,int,int",
145 "Display*a0,int a1,int a2",
146 "a0,a1,a2"
148 output_fn("XF86DGAGetViewPortSize",Status,
149 "Display*,int,int*,int*",
150 "Display*a0,int a1,int *a2,int *a3",
151 "a0,a1,a2,a3"
153 output_fn("XF86DGASetViewPort",Status,
154 "Display*,int,int,int",
155 "Display*a0,int a1,int a2,int a3",
156 "a0,a1,a2,a3"
158 output_fn("XF86DGAInstallColormap",Status,
159 "Display*,int,Colormap",
160 "Display*a0,int a1,Colormap a2",
161 "a0,a1,a2"
163 output_fn("XF86DGAQueryDirectVideo",Status,
164 "Display*,int,int*",
165 "Display*a0,int a1,int *a2",
166 "a0,a1,a2"
168 output_fn("XF86DGAViewPortChanged",Status,
169 "Display*,int,int",
170 "Display*a0,int a1,int a2",
171 "a0,a1,a2"
173 } else {
174 open(IN, "echo \"$x11_incl#include <X11/$extensions_dir$name.h>\" | gcc -L$X11_include_dir -E - | grep -v '^[ \t]*\$'|") || die "open";
176 PROTO: while(<IN>) {
177 if(m'extern\s+([^()]*)\b([a-zA-Z0-9_]+)\s*\(') {
178 $result_type = $1;
179 $fn_name = $2;
180 $result_type = "int" if $result_type =~ /^\s*$/;
181 @args = ();
182 while(<IN>) {
183 last if m'\)\s*;';
184 # Give up on vararg functions and function pointer args.
185 if(m'\.\.\.|\(\*\)') {
186 undef $fn_name;
187 last;
189 if(m'\s*([^,]*[^, \t])\s*(,?\n)') {
190 $args[$#args+1] = $1;
191 if ($1 =~ /char\s*\[/) { # small hack for XQueryKeymap
192 $args[$#args] = "char*";
196 # Skip if vararg, function pointer arg, or not needed.
197 next unless $fn_name;
198 next unless $want{$fn_name} && $want{$fn_name} == 1;
200 # Special case for no arguments (which is specified as "void").
201 if($#args == 0 && $args[0] eq "void") {
202 @args = ();
204 $proto = "";
205 $formals = "";
206 $actuals = "";
207 for($i = 0; $i <= $#args; $i++) {
208 $comma = $i < $#args ? ", " : "";
209 $proto .= "$args[$i]$comma";
210 $formals .= "$args[$i] a$i$comma";
211 $actuals .= "a$i$comma";
213 $proto = $formals = "void" if $#args == -1;
214 output_fn($fn_name, $result_type, $proto, $formals, $actuals);
219 if($name eq "Xlib") {
220 raw_output_fn("XSynchronize", "int (*r)(Display *)",
221 "int (*TSXSynchronize(Display *, Bool))(Display *)",
222 "int (*TSXSynchronize(Display *a0, Bool a1))(Display *)",
223 "a0, a1");
224 print OUTC "\nextern void _XInitImageFuncPtrs(XImage *);\n";
225 output_fn("_XInitImageFuncPtrs", "void", "XImage *", "XImage *a0", "a0");
226 } elsif($name eq "Xutil") {
227 output_fn("XDestroyImage", "int",
228 "struct _XImage *", "struct _XImage *a0", "a0");
229 output_fn("XGetPixel", "unsigned long",
230 "struct _XImage *, int, int",
231 "struct _XImage *a0, int a1, int a2",
232 "a0, a1, a2");
233 output_fn("XPutPixel", "int",
234 "struct _XImage *, int, int, unsigned long",
235 "struct _XImage *a0, int a1, int a2, unsigned long a3",
236 "a0, a1, a2, a3");
237 output_fn("XSubImage", "struct _XImage *",
238 "struct _XImage *, int, int, unsigned int, unsigned int",
239 "struct _XImage *a0, int a1, int a2, unsigned int a3, unsigned int a4",
240 "a0, a1, a2, a3, a4");
241 output_fn("XAddPixel", "int",
242 "struct _XImage *, long",
243 "struct _XImage *a0, long a1", "a0, a1");
244 output_fn("XUniqueContext", "XContext", "void", "void", "");
247 print OUTH <<END;
249 #endif /* __WINE_TS$ucname\_H */
251 print OUTC <<END;
252 $post_file
259 foreach $i (keys %want) {
260 if($want{$i} == 1) {
261 print "Unresolved: $i\n";
266 sub output_fn {
267 # Example call:
268 # output_fn("main", "int", "int, char **", "int a0, char **a1", "a0, a1")
271 my ($fn_name, $result_type, $protos, $formals, $actuals) = @_;
273 return raw_output_fn($fn_name,
274 $result_type =~ /^\s*void\s*$/ ? "" : "$result_type r",
275 "$result_type TS$fn_name($protos)",
276 "$result_type TS$fn_name($formals)",
277 $actuals);
280 sub raw_output_fn {
281 # Example call:
282 # output_fn("main", "int r", "int main(int, char **)", "int main(int a0, char **a1)", "a0, a1")
285 my ($fn_name, $resultdecl, $protodecl, $defdecl, $actuals) = @_;
287 return undef unless $want{$fn_name} && $want{$fn_name} == 1;
289 print OUTC "\n$defdecl\n";
290 print OUTH "extern $protodecl;\n";
291 # print OUTH "#define $fn_name TS$fn_name\n";
292 print OUTC "{\n";
293 print OUTC " $resultdecl;\n" if $resultdecl;
294 print OUTC " TRACE(x11, \"Call $fn_name\\n\");\n";
295 print OUTC " EnterCriticalSection( &X11DRV_CritSection );\n";
296 print OUTC " ";
297 print OUTC "r = " if $resultdecl;
298 print OUTC "$fn_name($actuals);\n";
299 print OUTC " LeaveCriticalSection( &X11DRV_CritSection );\n";
300 print OUTC " TRACE(x11, \"Ret $fn_name\\n\");\n";
301 print OUTC " return r;\n" if $resultdecl;
302 print OUTC "}\n";
303 $want{$fn_name} = 2;
304 return 1;