Find out how much data is available when calling ReadFileEx.
[wine] / tools / make_X11wrappers
1 #!/usr/bin/perl -w
2
3 # Create threads safe wrappers around X11 calls.
4 #
5 # Copyright 1998 Kristian Nielsen.
6 #
7
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/).
14 #
15 # This program expects to be run from Wine's main directory.
16
17 $X11_include_dir = "/usr/X11/include";
18 $outdir = "tsx11";
19 $wantfile = "$outdir/X11_calls";
20 @dolist = ("Xlib", "Xresource", "Xutil", "xpm", "XShm", "xf86dga", "xf86dga2", "xf86vmode", "shape", "xvideo", "Xrender");
21
22 # First read list of wanted function names.
23
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 '$_'";
32     }
33 }
34 close(WANT);
35
36 foreach $name (@dolist) {
37
38     $ucname = uc $name;
39     $lcname = lc $name;
40
41     $outfile = "/ts_$lcname";
42     open(OUTC, ">$outdir/$outfile.c") || die "open";
43     open(OUTH, ">include/$outfile.h") || die "open";
44
45     $x11_incl = "";
46     $extensions_dir = "";
47     $pre_file = "";
48     $post_file = "";
49     $inc_name = $name;
50     if($name eq "Xutil" || $name eq "Xresource" || $name eq "XShm") {
51         $x11_incl = "#include <X11/Xlib.h>\n";
52         # For Xutil, we need X11/Xresource.h for XUniqueContext().
53         $x11_incl .= "#include <X11/Xresource.h>\n" if $name eq "Xutil";
54     }
55     if($name eq "xf86dga")  {
56         $x11_incl = "#include <X11/Xlib.h>\n";
57         $extensions_dir = "extensions/";
58         $pre_file = "#ifdef HAVE_LIBXXF86DGA\n";
59         $post_file = "#endif /* defined(HAVE_LIBXXF86DGA) */\n";
60     }
61     if($name eq "xf86dga2")  {
62         $x11_incl = "#include <X11/Xlib.h>\n";
63         $extensions_dir = "extensions/";
64         $pre_file = "#ifdef HAVE_LIBXXF86DGA2\n";
65         $post_file = "#endif /* defined(HAVE_LIBXXF86DGA2) */\n";
66         $inc_name = "xf86dga";
67     }
68     if($name eq "XShm") {
69         $extensions_dir = "extensions/";
70         $pre_file = "#ifdef HAVE_LIBXXSHM\n";
71         $post_file = "#endif /* defined(HAVE_LIBXXSHM) */\n";
72     }
73     if($name eq "xpm") {
74         $pre_file = "#ifdef HAVE_LIBXXPM\n";
75         $post_file = "#endif /* defined(HAVE_LIBXXPM) */\n";
76     }
77     if($name eq "xf86vmode") {
78         $x11_incl = "#include <X11/Xlib.h>\n";
79         $extensions_dir = "extensions/";
80         $pre_file = "#include \"windef.h\"\n#ifdef HAVE_LIBXXF86VM\n#define XMD_H\n#include \"basetsd.h\"\n";
81         $post_file = "#endif /* defined(HAVE_LIBXXF86VM) */\n";
82     }
83     if($name eq "shape") {
84         $extensions_dir = "extensions/";
85         $pre_file = "#ifdef HAVE_LIBXSHAPE\n#include <X11/IntrinsicP.h>\n";
86         $post_file = "#endif /* defined(HAVE_LIBXSHAPE) */\n";
87         $inc_name = "shape";
88     }
89     if($name eq "xvideo")  {
90         $x11_incl = "#include <X11/Xlib.h>\n#include <X11/extensions/Xv.h>\n#include <X11/extensions/XShm.h>\n";
91         $extensions_dir = "extensions/";
92         $pre_file = "#ifdef HAVE_XVIDEO\n";
93         $post_file = "#endif /* defined(HAVE_XVIDEO) */\n";
94         $inc_name = "Xvlib";
95     }
96     if($name eq "Xrender")  {
97         $x11_incl = "#include <X11/Xlib.h>\n";
98         $extensions_dir = "extensions/";
99         $pre_file = "#ifdef HAVE_LIBXRENDER\n";
100         $post_file = "#endif /* defined(HAVE_LIBXRENDER) */\n";
101     }
102
103
104     print OUTH <<END;
105 /*
106  * Thread safe wrappers around $name calls.
107  * Always include this file instead of <X11/$name.h>.
108  * This file was generated automatically by tools/make_X11wrappers
109  * DO NOT EDIT!
110  */
111
112 #ifndef __WINE_TS_$ucname\_H
113 #define __WINE_TS_$ucname\_H
114
115 #ifndef __WINE_CONFIG_H
116 # error You must include config.h to use this header
117 #endif
118
119 $pre_file
120 $x11_incl#include <X11/$extensions_dir$inc_name.h>
121
122 extern void (*wine_tsx11_lock)(void);
123 extern void (*wine_tsx11_unlock)(void);
124
125 END
126
127     print OUTC <<END;
128 /*
129  * Thread safe wrappers around $name calls.
130  * This file was generated automatically by tools/make_X11wrappers
131  * DO NOT EDIT!
132  */
133
134 #include "config.h"
135
136 $pre_file
137 $x11_incl#include <X11/$extensions_dir$inc_name.h>
138
139 #include "ts_$lcname.h"
140
141 END
142
143     if($name eq "xpm") {        # Handle as special case.
144         output_fn("XpmCreatePixmapFromData", "int",
145                   "Display *, Drawable, char **, Pixmap *, Pixmap *, XpmAttributes *",
146                   "Display *a0, Drawable a1, char **a2, Pixmap *a3, Pixmap *a4, XpmAttributes *a5",
147                   "a0, a1, a2, a3, a4, a5");
148         output_fn("XpmAttributesSize", "int", "void", "void", "");
149     } elsif($name eq "XShm") {
150         output_fn("XShmQueryExtension", "Bool",
151                   "Display *", "Display *a0", "a0");
152         output_fn("XShmQueryVersion", "Bool",
153                   "Display *, int *, int *, Bool *", 
154                   "Display *a0, int *a1, int *a2, Bool *a3", "a0, a1, a2, a3");
155         output_fn("XShmPixmapFormat", "int",
156                   "Display *", "Display *a0", "a0");
157         output_fn("XShmAttach", Status,
158                   "Display *, XShmSegmentInfo *",
159                   "Display *a0, XShmSegmentInfo *a1", "a0, a1");
160         output_fn("XShmDetach", Status,
161                   "Display *, XShmSegmentInfo *",
162                   "Display *a0, XShmSegmentInfo *a1", "a0, a1");
163         output_fn("XShmPutImage", Status,
164                   "Display *, Drawable, GC, XImage *, int, int, int, int, unsigned int, unsigned int, Bool",
165                   "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");
166         output_fn("XShmGetImage", Status,
167                   "Display *, Drawable, XImage *, int, int, unsigned long",
168                   "Display *a0, Drawable a1, XImage *a2, int a3, int a4, unsigned long a5", 
169                   "a0, a1, a2, a3, a4, a5");
170         output_fn("XShmCreateImage", "XImage *",
171                   "Display *, Visual *, unsigned int, int, char *, XShmSegmentInfo *, unsigned int, unsigned int",
172                   "Display *a0, Visual *a1, unsigned int a2, int a3, char *a4, XShmSegmentInfo *a5, unsigned int a6, unsigned int a7",
173                   "a0, a1, a2, a3, a4, a5, a6, a7");
174         output_fn("XShmCreatePixmap", "Pixmap",
175                   "Display *, Drawable, char *, XShmSegmentInfo *, unsigned int, unsigned int, unsigned int",
176                   "Display *a0, Drawable a1, char *a2, XShmSegmentInfo *a3, unsigned int a4, unsigned int a5, unsigned int a6",
177                   "a0, a1, a2, a3, a4, a5, a6");
178     } elsif($name eq "xf86dga") {
179         output_fn("XF86DGAQueryVersion",Bool,
180                 "Display*,int*,int*",
181                 "Display*a0,int*a1,int*a2",
182                 "a0,a1,a2"
183         );
184         output_fn("XF86DGAQueryExtension",Bool,
185                 "Display*,int*,int*",
186                 "Display*a0,int*a1,int*a2",
187                 "a0,a1,a2"
188         );
189         output_fn("XF86DGAGetVideo",Status,
190                 "Display*,int,char**,int*,int*,int*",
191                 "Display*a0,int a1,char**a2,int*a3,int*a4,int*a5",
192                 "a0,a1,a2,a3,a4,a5"
193         );
194         output_fn("XF86DGADirectVideo",Status,
195                 "Display*,int,int",
196                 "Display*a0,int a1,int a2",
197                 "a0,a1,a2"
198         );
199         output_fn("XF86DGAGetViewPortSize",Status,
200                 "Display*,int,int*,int*",
201                 "Display*a0,int a1,int *a2,int *a3",
202                 "a0,a1,a2,a3"
203         );
204         output_fn("XF86DGASetViewPort",Status,
205                 "Display*,int,int,int",
206                 "Display*a0,int a1,int a2,int a3",
207                 "a0,a1,a2,a3"
208         );
209         output_fn("XF86DGAInstallColormap",Status,
210                 "Display*,int,Colormap",
211                 "Display*a0,int a1,Colormap a2",
212                 "a0,a1,a2"
213         );
214         output_fn("XF86DGAQueryDirectVideo",Status,
215                 "Display*,int,int*",
216                 "Display*a0,int a1,int *a2",
217                 "a0,a1,a2"
218         );
219         output_fn("XF86DGAViewPortChanged",Status,
220                 "Display*,int,int",
221                 "Display*a0,int a1,int a2",
222                 "a0,a1,a2"
223         );
224     } elsif($name eq "xf86dga2") {
225         output_fn_short("Bool", "XDGAQueryVersion", "Display*" ,"int*","int*");
226         output_fn_short("Bool", "XDGAQueryExtension", "Display*" ,"int*","int*");
227         output_fn_short("XDGAMode*", "XDGAQueryModes", "Display*" ,"int", "int*");
228         output_fn_short("XDGADevice*", "XDGASetMode", "Display*" ,"int","int");
229         output_fn_short("Bool", "XDGAOpenFramebuffer", "Display*" ,"int");
230         output_fn_short("void", "XDGACloseFramebuffer", "Display*" ,"int");
231         output_fn_short("void", "XDGASetViewport", "Display*" ,"int", "int", "int", "int");
232         output_fn_short("void", "XDGAInstallColormap", "Display*" , "int", "Colormap");
233         output_fn_short("Colormap", "XDGACreateColormap", "Display*" ,"int", "XDGADevice*", "int");
234         output_fn_short("void", "XDGASelectInput", "Display*" ,"int", "long");
235         output_fn_short("void", "XDGAFillRectangle", "Display*" ,"int", "int", "int", "unsigned int", "unsigned int", "unsigned long");
236         output_fn_short("void", "XDGACopyArea", "Display*" ,"int", "int", "int", "unsigned int", "unsigned int", "int", "int");
237         output_fn_short("void", "XDGACopyTransparentArea", "Display*" ,"int", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned long");
238         output_fn_short("int", "XDGAGetViewportStatus", "Display*" ,"int");
239         output_fn_short("void", "XDGASync", "Display*" ,"int");
240         output_fn_short("Bool", "XDGASetClientVersion", "Display*");
241         output_fn_short("void", "XDGAChangePixmapMode", "Display*" ,"int", "int*", "int*", "int");
242         output_fn_short("void", "XDGAKeyEventToXKeyEvent", "XDGAKeyEvent*" ,"XKeyEvent*");
243     } elsif ($name eq "xvideo") {
244         output_fn_short("int", "XvQueryExtension", "Display*", "unsigned int*", "unsigned int*", "unsigned int*", "unsigned int*", "unsigned int*");
245         output_fn_short("int", "XvQueryAdaptors", "Display*", "Window", "unsigned int*", "XvAdaptorInfo**");
246         output_fn_short("int", "XvQueryEncodings", "Display*", "XvPortID", "unsigned int*", "XvEncodingInfo**");
247         output_fn_short("int", "XvPutVideo", "Display*", "XvPortID", "Drawable", "GC", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned int", "unsigned int");
248         output_fn_short("int", "XvPutStill", "Display*", "XvPortID", "Drawable", "GC", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned int", "unsigned int");
249         output_fn_short("int", "XvGetVideo", "Display*", "XvPortID", "Drawable", "GC", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned int", "unsigned int");
250         output_fn_short("int", "XvGetStill", "Display*", "XvPortID", "Drawable", "GC", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned int", "unsigned int");
251         output_fn_short("int", "XvStopVideo", "Display*", "XvPortID", "Drawable");
252         output_fn_short("int", "XvGrabPort", "Display*", "XvPortID", "Time");
253         output_fn_short("int", "XvUngrabPort", "Display*", "XvPortID", "Time");
254         output_fn_short("int", "XvSelectVideoNotify", "Display*", "Drawable", "Bool");
255         output_fn_short("int", "XvSelectPortNotify", "Display*", "XvPortID", "Bool");
256         output_fn_short("int", "XvSetPortAttribute", "Display*", "XvPortID", "Atom", "int");
257         output_fn_short("int", "XvGetPortAttribute", "Display*", "XvPortID", "Atom", "int*");
258         output_fn_short("int", "XvQueryBestSize", "Display*", "XvPortID", "Bool", "unsigned int", "unsigned int", "unsigned int", "unsigned int", "unsigned int*", "unsigned int*");
259         output_fn_short("XvAttribute*", "XvQueryPortAttributes", "Display*", "XvPortID", "int*");
260         output_fn_short("void", "XvFreeAdaptorInfo", "XvAdaptorInfo*");
261         output_fn_short("void", "XvFreeEncodingInfo", "XvEncodingInfo*");
262         output_fn_short("XvImageFormatValues *", "XvListImageFormats", "Display*", "XvPortID", "int*");
263         output_fn_short("XvImage *", "XvCreateImage", "Display*", "XvPortID", "int", "char*", "int", "int");
264         output_fn_short("int", "XvPutImage", "Display*", "XvPortID", "Drawable", "GC", "XvImage*", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned int", "unsigned int");
265         output_fn_short("int", "XvShmPutImage", "Display*", "XvPortID", "Drawable", "GC", "XvImage*", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned int", "unsigned int", "Bool");
266 output_fn_short("XvImage *", "XvShmCreateImage", "Display*", "XvPortID", "int", "char*", "int", "int", "XShmSegmentInfo*");
267     } elsif($name eq "xf86vmode") {
268         output_fn("XF86VidModeQueryVersion",Bool,
269                 "Display*,int*,int*",
270                 "Display*a0,int*a1,int*a2",
271                 "a0,a1,a2"
272         );
273         output_fn("XF86VidModeQueryExtension",Bool,
274                 "Display*,int*,int*",
275                 "Display*a0,int*a1,int*a2",
276                 "a0,a2,a2"
277         );
278         output_fn("XF86VidModeGetModeLine",Bool,
279                 "Display*,int,int*,XF86VidModeModeLine*",
280                 "Display*a0,int a1,int*a2,XF86VidModeModeLine*a3",
281                 "a0,a1,a2,a3"
282         );
283         output_fn("XF86VidModeGetAllModeLines",Bool,
284                 "Display*,int,int*,XF86VidModeModeInfo***",
285                 "Display*a0,int a1,int*a2,XF86VidModeModeInfo***a3",
286                 "a0,a1,a2,a3"
287         );
288         output_fn("XF86VidModeAddModeLine",Bool,
289                 "Display*,int,XF86VidModeModeInfo*,XF86VidModeModeInfo*",
290                 "Display*a0,int a1,XF86VidModeModeInfo*a2,XF86VidModeModeInfo*a3",
291                 "a0,a1,a2,a3"
292         );
293         output_fn("XF86VidModeDeleteModeLine",Bool,
294                 "Display*,int,XF86VidModeModeInfo*",
295                 "Display*a0,int a1,XF86VidModeModeInfo*a2",
296                 "a0,a1,a2"
297         );
298         output_fn("XF86VidModeModModeLine",Bool,
299                 "Display*,int,XF86VidModeModeLine*",
300                 "Display*a0,int a1,XF86VidModeModeLine*a2",
301                 "a0,a1,a2"
302         );
303         output_fn("XF86VidModeValidateModeLine",Status,
304                 "Display*,int,XF86VidModeModeInfo*",
305                 "Display*a0,int a1,XF86VidModeModeInfo*a2",
306                 "a0,a1,a2"
307         );
308         output_fn("XF86VidModeSwitchMode",Bool,
309                 "Display*,int,int",
310                 "Display*a0,int a1,int a2",
311                 "a0,a1,a2"
312         );
313         output_fn("XF86VidModeSwitchToMode",Bool,
314                 "Display*,int,XF86VidModeModeInfo*",
315                 "Display*a0,int a1,XF86VidModeModeInfo*a2",
316                 "a0,a1,a2"
317         );
318         output_fn("XF86VidModeLockModeSwitch",Bool,
319                 "Display*,int,int",
320                 "Display*a0,int a1,int a2",
321                 "a0,a1,a2"
322         );
323         output_fn("XF86VidModeGetMonitor",Bool,
324                 "Display*,int,XF86VidModeMonitor*",
325                 "Display*a0,int a1,XF86VidModeMonitor*a2",
326                 "a0,a1,a2"
327         );
328         output_fn("XF86VidModeGetViewPort",Bool,
329                 "Display*,int,int*,int*",
330                 "Display*a0,int a1,int*a2,int*a3",
331                 "a0,a1,a2,a3"
332         );
333         output_fn("XF86VidModeSetViewPort",Bool,
334                 "Display*,int,int,int",
335                 "Display*a0,int a1,int a2,int a3",
336                 "a0,a1,a2,a3"
337         );      
338     } elsif($name eq "Xrender") {
339         output_fn("XRenderAddGlyphs","void",
340                 "Display*,GlyphSet,Glyph*,XGlyphInfo*,int,char*,int",
341                 "Display*a0,GlyphSet a1,Glyph*a2,XGlyphInfo*a3,int a4,char*a5,int a6",
342                 "a0,a1,a2,a3,a4,a5,a6"
343         );
344         output_fn("XRenderCompositeString8","void",
345                 "Display*,int,Picture,Picture,XRenderPictFormat*,GlyphSet,int,int,int,int,char*,int",
346                 "Display*a0,int a1,Picture a2,Picture a3,XRenderPictFormat*a4,GlyphSet a5,int a6,int a7,int a8,int a9,char*a10,int a11",
347                 "a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11"
348         );
349         output_fn("XRenderCompositeString16","void",
350                 "Display*,int,Picture,Picture,XRenderPictFormat*,GlyphSet,int,int,int,int,unsigned short*,int",
351                 "Display*a0,int a1,Picture a2,Picture a3,XRenderPictFormat*a4,GlyphSet a5,int a6,int a7,int a8,int a9,unsigned short*a10,int a11",
352                 "a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11"
353         );
354         output_fn("XRenderCompositeString32","void",
355                 "Display*,int,Picture,Picture,XRenderPictFormat*,GlyphSet,int,int,int,int,unsigned int*,int",
356                 "Display*a0,int a1,Picture a2,Picture a3,XRenderPictFormat*a4,GlyphSet a5,int a6,int a7,int a8,int a9,unsigned int*a10,int a11",
357                 "a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11"
358         );
359         output_fn("XRenderCreateGlyphSet",GlyphSet,
360                 "Display*,XRenderPictFormat*",
361                 "Display*a0,XRenderPictFormat*a1",
362                 "a0,a1"
363         );
364         output_fn("XRenderCreatePicture",Picture,
365                 "Display*,Drawable,XRenderPictFormat*,unsigned long,XRenderPictureAttributes*",
366                 "Display*a0,Drawable a1,XRenderPictFormat*a2,unsigned long a3,XRenderPictureAttributes*a4",
367                 "a0,a1,a2,a3,a4"
368         );
369         output_fn("XRenderFillRectangle","void",
370                 "Display*,int,Picture,XRenderColor*,int,int,unsigned int, unsigned int",
371                 "Display*a0,int a1,Picture a2,XRenderColor*a3,int a4,int a5,unsigned int a6,unsigned int a7",
372                 "a0,a1,a2,a3,a4,a5,a6,a7"
373         );
374         output_fn("XRenderFindFormat","XRenderPictFormat*",
375                 "Display*,unsigned long,XRenderPictFormat*,int",
376                 "Display*a0,unsigned long a1,XRenderPictFormat*a2,int a3",
377                 "a0,a1,a2,a3"
378         );
379         output_fn("XRenderFindVisualFormat","XRenderPictFormat*",
380                 "Display*,Visual*",
381                 "Display*a0,Visual*a1",
382                 "a0,a1"
383         );
384         output_fn("XRenderFreeGlyphSet","void",
385                 "Display*,GlyphSet",
386                 "Display*a0,GlyphSet a1",
387                 "a0,a1"
388         );
389         output_fn("XRenderFreePicture","void",
390                 "Display*,Picture",
391                 "Display*a0,Picture a1",
392                 "a0,a1"
393         );
394         output_fn("XRenderSetPictureClipRectangles","void",
395                 "Display*,Picture,int,int,XRectangle*,int",
396                 "Display*a0,Picture a1,int a2,int a3,XRectangle* a4,int a5",
397                 "a0,a1,a2,a3,a4,a5"
398         );
399         output_fn("XRenderQueryExtension",Bool,
400                 "Display*,int*,int*",
401                 "Display*a0,int*a1,int*a2",
402                 "a0,a1,a2"
403         );
404         
405     } else {
406         open(IN, 
407              "echo \"$x11_incl#include <X11/$extensions_dir$name.h>\" | " . 
408              "gcc -L$X11_include_dir -DNeedFunctionPrototypes -E - | " .
409              "grep -v '^[ \t]*\$)' |"
410              ) || die "open";
411
412       PROTO: while(<IN>) {
413           if(m'extern\s+([^()]*)\b([a-zA-Z0-9_]+)\s*\(') {
414               $result_type = $1;
415               $fn_name = $2;
416               $result_type = "int" if $result_type =~ /^\s*$/;
417               @args = ();
418               while(<IN>) {
419                   last if m'\)\s*;';
420                   # Give up on vararg functions and function pointer args.
421                   if(m'\.\.\.|\(\*\)') {
422                       undef $fn_name;
423                       last;
424                   }
425                   if(m'\s*([^,]*[^, \t])\s*(,?\n)') {
426                       $args[$#args+1] = $1;
427                       if ($1 =~ /char\s*\[/) { # small hack for XQueryKeymap
428                         $args[$#args] = "char*";
429                       }
430                   }
431               }
432               # Skip if vararg, function pointer arg, or not needed.
433               next unless $fn_name;
434               next unless $want{$fn_name} && $want{$fn_name} == 1;
435
436               # Special case for no arguments (which is specified as "void").
437               if($#args == 0 && $args[0] eq "void") {
438                   @args = ();
439               }
440               $proto = "";
441               $formals = "";
442               $actuals = "";
443               for($i = 0; $i <= $#args; $i++) {
444                   $comma = $i < $#args ? ", " : "";
445                   $proto .= "$args[$i]$comma";
446                   $formals .= "$args[$i] a$i$comma";
447                   $actuals .= "a$i$comma";
448               }
449               $proto = $formals = "void" if $#args == -1;
450               output_fn($fn_name, $result_type, $proto, $formals, $actuals);
451           }
452       }
453     }
454
455     if($name eq "Xlib") {
456         raw_output_fn("XSynchronize", "int (*r)(Display *)",
457                   "int (*TSXSynchronize(Display *, Bool))(Display *)",
458                   "int (*TSXSynchronize(Display *a0, Bool a1))(Display *)",
459                   "a0, a1");
460         print OUTC "\nextern void _XInitImageFuncPtrs(XImage *);\n";
461         output_fn("_XInitImageFuncPtrs", "void", "XImage *", "XImage *a0", "a0");
462     } elsif($name eq "Xutil") {
463         output_fn("XDestroyImage", "int",
464                   "struct _XImage *", "struct _XImage *a0", "a0");
465         output_fn("XGetPixel", "unsigned long",
466                   "struct _XImage *, int, int",
467                   "struct _XImage *a0, int a1, int a2",
468                   "a0, a1, a2");
469         output_fn("XPutPixel", "int",
470                   "struct _XImage *, int, int, unsigned long",
471                   "struct _XImage *a0, int a1, int a2, unsigned long a3",
472                   "a0, a1, a2, a3");
473         output_fn("XSubImage", "struct _XImage *",
474                   "struct _XImage *, int, int, unsigned int, unsigned int",
475                   "struct _XImage *a0, int a1, int a2, unsigned int a3, unsigned int a4",
476                   "a0, a1, a2, a3, a4");
477         output_fn("XAddPixel", "int",
478                   "struct _XImage *, long",
479                   "struct _XImage *a0, long a1", "a0, a1");
480         output_fn("XUniqueContext", "XContext", "void", "void", "");
481         output_fn("XDeleteContext", "int",
482                   "Display*,XID,XContext",
483                   "Display*a0,XID a1,XContext a2",
484                   "a0,a1,a2");
485     }
486
487     print OUTH <<END;
488
489 $post_file
490 #endif /* __WINE_TS_$ucname\_H */
491 END
492     print OUTC <<END;
493
494 $post_file
495 END
496
497
498
499 }
500
501 foreach $i (keys %want) {
502     if($want{$i} == 1) {
503         print "Unresolved: $i\n";
504     }
505 }
506
507
508 sub output_fn {
509     # Example call:
510     # output_fn("main", "int", "int, char **", "int a0, char **a1", "a0, a1")
511     #
512
513     my ($fn_name, $result_type, $protos, $formals, $actuals) = @_;
514
515     return raw_output_fn($fn_name,
516                          $result_type =~ /^\s*void\s*$/ ? "" : "$result_type r",
517                          "$result_type TS$fn_name($protos)",
518                          "$result_type TS$fn_name($formals)",
519                          $actuals);
520 }
521
522 sub output_fn_short {
523     # Example call:
524     # output_fn_sort("Bool", "XDGAQueryExtension", "Display *", "int *", "int *");
525     #
526     my ($result_type, $fn_name, @args) = @_;
527     
528     my ($i, $proto, $formals, $actuals) = (0, 
529                                            "$result_type TS$fn_name(",
530                                            "$result_type TS$fn_name(",
531                                            "");
532     while ($val = shift @args) {
533         $proto = $proto . $val;
534         $formals = $formals . $val . " a$i";
535         $actuals = $actuals . " a$i";
536         $i++;
537         if (@args) {
538             $proto = $proto . ", ";
539             $formals = $formals . ", ";
540             $actuals = $actuals . ", ";
541         }
542     }
543     $proto = $proto . ")";
544     $formals = $formals . ")";
545
546
547     raw_output_fn($fn_name,
548                   $result_type =~ /^\s*void\s*$/ ? "" : "$result_type r",
549                   $proto,
550                   $formals,
551                   $actuals);
552 }
553
554 sub raw_output_fn {
555     # Example call:
556     # output_fn("main", "int r", "int main(int, char **)", "int main(int a0, char **a1)", "a0, a1")
557     #
558
559     my ($fn_name, $resultdecl, $protodecl, $defdecl, $actuals) = @_;
560
561     return undef unless $want{$fn_name} && $want{$fn_name} == 1;
562
563     print OUTC "\n$defdecl\n";
564     print OUTH "extern $protodecl;\n";
565 #    print OUTH "#define $fn_name TS$fn_name\n";
566     print OUTC "{\n";
567     print OUTC "  $resultdecl;\n" if $resultdecl;
568     print OUTC "  wine_tsx11_lock();\n";
569     print OUTC "  ";
570     print OUTC "r = " if $resultdecl;
571     print OUTC "$fn_name($actuals);\n";
572     print OUTC "  wine_tsx11_unlock();\n";
573     print OUTC "  return r;\n" if $resultdecl;
574     print OUTC "}\n";
575     $want{$fn_name} = 2;
576     return 1;
577 }