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