3 # Create threads safe wrappers around X11 calls.
5 # Copyright 1998 Kristian Nielsen.
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # FIXME: This does not do full C prototype parsing, but relies on
22 # knowledge on how the X11 include files are formatted. It will
23 # probably need to be modified for new include files. It also fails
24 # for certain prototypes (notably those with function pointer
25 # arguments or results), so these must be added manually. And it
26 # relies on a fixed location of X11 includes (/usr/X11R6/include/).
28 # This program expects to be run from Wine's main directory.
30 $X11_include_dir = "/usr/X11/include";
31 $outdir = "dlls/x11drv";
32 $wantfile = "$outdir/X11_calls";
35 # First read list of wanted function names.
37 open(WANT, $wantfile) || die "open";
39 next if /^\s*\#/; # Skip comment lines.
40 next if /^\s*$/; # Skip empty lines.
41 if(/^\s*([a-zA-Z0-9_]+)\s*$/) {
44 die "syntax error in file '$wantfile', in line '$_'";
49 foreach $name (@dolist) {
54 $outfile = "/ts_$lcname";
55 open(OUTC, ">$outdir/$outfile.c") || die "open";
56 open(OUTH, ">$outdir/$outfile.h") || die "open";
60 $pre_file = "#ifdef HAVE_X11_XLIB_H\n";
61 $post_file = "#endif /* defined(HAVE_X11_XLIB_H) */\n";
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
72 #ifndef __WINE_TS_$ucname\_H
73 #define __WINE_TS_$ucname\_H
75 #ifndef __WINE_CONFIG_H
76 # error You must include config.h to use this header
80 $x11_incl#include <X11/$extensions_dir$inc_name.h>
82 extern void wine_tsx11_lock(void);
83 extern void wine_tsx11_unlock(void);
89 * Thread safe wrappers around $name calls.
90 * This file was generated automatically by tools/make_X11wrappers
97 $x11_incl#include <X11/$extensions_dir$inc_name.h>
99 #include "ts_$lcname.h"
104 "echo \"$x11_incl#include <X11/$extensions_dir$name.h>\" | " .
105 "gcc -L$X11_include_dir -DNeedFunctionPrototypes -E - | " .
106 "grep -v '^[ \t]*\$)' |"
110 if(m'extern\s+([^()]*)\b([a-zA-Z0-9_]+)\s*\(') {
113 $result_type = "int" if $result_type =~ /^\s*$/;
117 # Give up on vararg functions and function pointer args.
118 if(m'\.\.\.|\(\*\)') {
122 if(m'\s*([^,]*[^, \t])\s*(,?\n)') {
123 $args[$#args+1] = $1;
124 if ($1 =~ /char\s*\[/) { # small hack for XQueryKeymap
125 $args[$#args] = "char*";
129 # Skip if vararg, function pointer arg, or not needed.
130 next unless $fn_name;
131 next unless $want{$fn_name} && $want{$fn_name} == 1;
133 # Special case for no arguments (which is specified as "void").
134 if($#args == 0 && $args[0] eq "void") {
140 for($i = 0; $i <= $#args; $i++) {
141 $comma = $i < $#args ? ", " : "";
142 $proto .= "$args[$i]$comma";
143 $formals .= "$args[$i] a$i$comma";
144 $actuals .= "a$i$comma";
146 $proto = $formals = "void" if $#args == -1;
147 output_fn($fn_name, $result_type, $proto, $formals, $actuals);
154 #endif /* __WINE_TS_$ucname\_H */
156 print OUTC "\n", $post_file;
159 foreach $i (keys %want) {
161 print "Unresolved: $i\n";
168 # output_fn("main", "int", "int, char **", "int a0, char **a1", "a0, a1")
171 my ($fn_name, $result_type, $protos, $formals, $actuals) = @_;
173 return raw_output_fn($fn_name,
174 $result_type =~ /^\s*void\s*$/ ? "" : "$result_type r",
175 "$result_type TS$fn_name($protos)",
176 "$result_type TS$fn_name($formals)",
180 sub output_fn_short {
182 # output_fn_sort("Bool", "XDGAQueryExtension", "Display *", "int *", "int *");
184 my ($result_type, $fn_name, @args) = @_;
186 my ($i, $proto, $formals, $actuals) = (0,
187 "$result_type TS$fn_name(",
188 "$result_type TS$fn_name(",
190 while ($val = shift @args) {
191 $proto = $proto . $val;
192 $formals = $formals . $val . " a$i";
193 $actuals = $actuals . " a$i";
196 $proto = $proto . ", ";
197 $formals = $formals . ", ";
198 $actuals = $actuals . ", ";
201 $proto = $proto . ")";
202 $formals = $formals . ")";
205 raw_output_fn($fn_name,
206 $result_type =~ /^\s*void\s*$/ ? "" : "$result_type r",
214 # output_fn("main", "int r", "int main(int, char **)", "int main(int a0, char **a1)", "a0, a1")
217 my ($fn_name, $resultdecl, $protodecl, $defdecl, $actuals) = @_;
219 return undef unless $want{$fn_name} && $want{$fn_name} == 1;
221 print OUTC "\n$defdecl\n";
222 print OUTH "extern $protodecl;\n";
223 # print OUTH "#define $fn_name TS$fn_name\n";
225 print OUTC " $resultdecl;\n" if $resultdecl;
226 print OUTC " wine_tsx11_lock();\n";
228 print OUTC "r = " if $resultdecl;
229 print OUTC "$fn_name($actuals);\n";
230 print OUTC " wine_tsx11_unlock();\n";
231 print OUTC " return r;\n" if $resultdecl;