In WM_DRAWITEM, always calls the app with a valid current focus_item.
[wine.git] / tools / make_requests
bloba0f07b1498170eecc442a3a108d12a96b015c82a
1 #! /usr/bin/perl -w
3 # Build the server/trace.c and server/request.h files
4 # from the contents of include/server.h.
6 # Copyright (C) 1998 Alexandre Julliard
9 %formats =
11 "int" => "%d",
12 "char" => "%c",
13 "unsigned char" => "%02x",
14 "unsigned int" => "%08x",
15 "void*" => "%p",
16 "time_t" => "%ld",
17 "path_t" => "&dump_path_t",
18 "char[1]" => "&dump_string",
19 "WCHAR[1]" => "&dump_unicode_string"
22 my @requests = ();
23 my %replies = ();
25 open(SERVER,"include/server.h") or die "Can't open include/server.h";
27 ### Parse server.h to find request/reply structure definitions
29 my @trace_lines = ();
30 my $protocol = 0; # server protocol version
32 while (<SERVER>)
34 if (/^struct +(\w+)_request/) { &DO_REQUEST($1); }
35 if (/^\#define SERVER_PROTOCOL_VERSION (\d+)/) { $protocol = $1 + 1; }
38 ### Output the dumping function tables
40 push @trace_lines, "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n";
41 foreach $req (@requests)
43 push @trace_lines, " (dump_func)dump_${req}_request,\n";
45 push @trace_lines, "};\n\n";
47 push @trace_lines, "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n";
48 foreach $req (@requests)
50 push @trace_lines, " (dump_func)", $replies{$req} ? "dump_${req}_reply,\n" : "0,\n";
52 push @trace_lines, "};\n\n";
54 push @trace_lines, "static const char * const req_names[REQ_NB_REQUESTS] = {\n";
55 foreach $req (@requests)
57 push @trace_lines, " \"$req\",\n";
59 push @trace_lines, "};\n";
61 REPLACE_IN_FILE( "server/trace.c", @trace_lines );
63 ### Replace the request list in server.h by the new values
65 my @server_lines = ();
67 push @server_lines, "enum request\n{\n";
68 foreach $req (@requests) { push @server_lines, " REQ_\U$req,\n"; }
69 push @server_lines, " REQ_NB_REQUESTS\n};\n\n";
70 push @server_lines, "union generic_request\n{\n";
71 push @server_lines, " struct request_max_size max_size;\n";
72 push @server_lines, " struct request_header header;\n";
73 foreach $req (@requests) { push @server_lines, " struct ${req}_request $req;\n"; }
74 push @server_lines, "};\n\n";
75 push @server_lines, "#define SERVER_PROTOCOL_VERSION $protocol\n";
77 REPLACE_IN_FILE( "include/server.h", @server_lines );
79 ### Output the request handlers list
81 my @request_lines = ();
83 foreach $req (@requests) { push @request_lines, "DECL_HANDLER($req);\n"; }
84 push @request_lines, "\n#ifdef WANT_REQUEST_HANDLERS\n\n";
85 push @request_lines, "typedef void (*req_handler)( void *req );\n";
86 push @request_lines, "static const req_handler req_handlers[REQ_NB_REQUESTS] =\n{\n";
87 foreach $req (@requests)
89 push @request_lines, " (req_handler)req_$req,\n";
91 push @request_lines, "};\n#endif /* WANT_REQUEST_HANDLERS */\n";
93 REPLACE_IN_FILE( "server/request.h", @request_lines );
95 ### Handle a request structure definition
97 sub DO_REQUEST
99 my $name = shift;
100 my @in_struct = ();
101 my @out_struct = ();
102 my $got_header = 0;
103 while (<SERVER>)
105 my ($dir, $type, $var);
106 last if /^};$/;
107 next if /^{$/;
108 s!/\*.*\*/!!g;
109 next if /^\s*$/;
110 if (/REQUEST_HEADER/)
112 die "Duplicated header" if $got_header;
113 die "Header must be first" if ($#in_struct != -1 || $#out_struct != -1);
114 $got_header++;
115 next;
117 if (/^\s*(IN|OUT)\s*VARARG\((\w+),(\w+)\)/)
119 $dir = $1;
120 $var = $2;
121 $type = "&dump_varargs_" . $3;
123 elsif (/^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/)
125 $dir = $1;
126 $type = $2 . ($5 || "");
127 $var = $4;
128 die "Unrecognized type $type" unless (defined($formats{$type}) || $5);
130 else
132 die "Unrecognized syntax $_";
134 if ($dir =~ /IN/) { push @in_struct, $type, $var; }
135 if ($dir =~ /OUT/) { push @out_struct, $type, $var; }
137 die "Missing header" unless $got_header;
138 push @requests, $name;
139 &DO_DUMP_FUNC( $name, "request", @in_struct);
140 if ($#out_struct >= 0)
142 $replies{$name} = 1;
143 &DO_DUMP_FUNC( $name, "reply", @out_struct);
147 ### Generate a dumping function
149 sub DO_DUMP_FUNC
151 my $name = shift;
152 my $req = shift;
153 push @trace_lines, "static void dump_${name}_$req( const struct ${name}_request *req )\n{\n";
154 while ($#_ >= 0)
156 my $type = shift;
157 my $var = shift;
158 if (defined($formats{$type}))
160 if ($formats{$type} =~ /^&(.*)/)
162 my $func = $1;
163 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
164 if ($type =~ /[1]/) { push @trace_lines, " $func( req, req->$var );\n"; }
165 else { push @trace_lines, " $func( req, &req->$var );\n"; }
166 push @trace_lines, " fprintf( stderr, \",\" );\n" if ($#_ > 0);
168 else
170 push @trace_lines, " fprintf( stderr, \" $var=$formats{$type}";
171 push @trace_lines, "," if ($#_ > 0);
172 push @trace_lines, "\", ";
173 push @trace_lines, "req->$var );\n";
176 else # must be some varargs format
178 if ($type =~ /^&(.*)/)
180 my $func = $1;
181 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
182 push @trace_lines, " $func( get_req_data(req), get_req_data_size(req) );\n";
184 else
186 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
187 push @trace_lines, " dump_varargs_${name}_${req}( req );\n";
191 push @trace_lines, "}\n\n";
194 ### Replace the contents of a file between ### make_requests ### marks
196 sub REPLACE_IN_FILE
198 my $name = shift;
199 my @data = @_;
200 my @lines = ();
201 open(FILE,$name) or die "Can't open $name";
202 while (<FILE>)
204 push @lines, $_;
205 last if /\#\#\# make_requests begin \#\#\#/;
207 push @lines, "\n", @data;
208 while (<FILE>)
210 if (/\#\#\# make_requests end \#\#\#/) { push @lines, "\n", $_; last; }
212 push @lines, <FILE>;
213 open(FILE,">$name") or die "Can't modify $name";
214 print FILE @lines;
215 close(FILE);