3 # Build the server/trace.c and server/request.h files
4 # from the contents of include/wine/server.h.
6 # Copyright (C) 1998 Alexandre Julliard
14 "unsigned char" => "%02x",
15 "unsigned short"=> "%04x",
16 "unsigned int" => "%08x",
22 "user_handle_t" => "%08x",
23 "rectangle_t" => "&dump_rectangle",
24 "char_info_t" => "&dump_char_info",
32 # Get the server protocol version
33 my $protocol = &GET_PROTOCOL_VERSION
;
35 ### Create server_protocol.h and print header
37 open SERVER_PROT
, ">include/wine/server_protocol.h" or die "Cannot create include/wine/server_protocol.h";
38 print SERVER_PROT
"/*\n * Wine server protocol definitions\n *\n";
39 print SERVER_PROT
" * This file is automatically generated; DO NO EDIT!\n";
40 print SERVER_PROT
" * Edit server/protocol.def instead and re-run tools/make_requests\n";
41 print SERVER_PROT
" */\n\n";
42 print SERVER_PROT
"#ifndef __WINE_WINE_SERVER_PROTOCOL_H\n";
43 print SERVER_PROT
"#define __WINE_WINE_SERVER_PROTOCOL_H\n";
45 ### Parse requests to find request/reply structure definitions
49 ### Build the request list and structures
51 print SERVER_PROT
"\n\nenum request\n{\n";
52 foreach $req (@requests) { print SERVER_PROT
" REQ_$req,\n"; }
53 print SERVER_PROT
" REQ_NB_REQUESTS\n};\n\n";
55 print SERVER_PROT
"union generic_request\n{\n";
56 print SERVER_PROT
" struct request_max_size max_size;\n";
57 print SERVER_PROT
" struct request_header request_header;\n";
58 foreach $req (@requests) { print SERVER_PROT
" struct ${req}_request ${req}_request;\n"; }
59 print SERVER_PROT
"};\n";
61 print SERVER_PROT
"union generic_reply\n{\n";
62 print SERVER_PROT
" struct request_max_size max_size;\n";
63 print SERVER_PROT
" struct reply_header reply_header;\n";
64 foreach $req (@requests) { print SERVER_PROT
" struct ${req}_reply ${req}_reply;\n"; }
65 print SERVER_PROT
"};\n\n";
67 printf SERVER_PROT
"#define SERVER_PROTOCOL_VERSION %d\n\n", $protocol + 1;
68 print SERVER_PROT
"#endif /* __WINE_WINE_SERVER_PROTOCOL_H */\n";
71 ### Output the dumping function tables
73 push @trace_lines, "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n";
74 foreach $req (@requests)
76 push @trace_lines, " (dump_func)dump_${req}_request,\n";
78 push @trace_lines, "};\n\n";
80 push @trace_lines, "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n";
81 foreach $req (@requests)
83 push @trace_lines, " (dump_func)", $replies{$req} ?
"dump_${req}_reply,\n" : "0,\n";
85 push @trace_lines, "};\n\n";
87 push @trace_lines, "static const char * const req_names[REQ_NB_REQUESTS] = {\n";
88 foreach $req (@requests)
90 push @trace_lines, " \"$req\",\n";
92 push @trace_lines, "};\n";
94 REPLACE_IN_FILE
( "server/trace.c", @trace_lines );
96 ### Output the request handlers list
98 my @request_lines = ();
100 foreach $req (@requests) { push @request_lines, "DECL_HANDLER($req);\n"; }
101 push @request_lines, "\n#ifdef WANT_REQUEST_HANDLERS\n\n";
102 push @request_lines, "typedef void (*req_handler)( const void *req, void *reply );\n";
103 push @request_lines, "static const req_handler req_handlers[REQ_NB_REQUESTS] =\n{\n";
104 foreach $req (@requests)
106 push @request_lines, " (req_handler)req_$req,\n";
108 push @request_lines, "};\n#endif /* WANT_REQUEST_HANDLERS */\n";
110 REPLACE_IN_FILE
( "server/request.h", @request_lines );
112 ### Parse the request definitions
116 # states: 0 = header 1 = declarations 2 = inside @REQ 3 = inside @REPLY
122 open(PROTOCOL
,"server/protocol.def") or die "Can't open server/protocol.def";
129 # strip white space at end of line
134 die "Misplaced \@HEADER" unless $state == 0;
139 # ignore everything while in state 0
142 if (/^\@REQ\(\s*(\w+)\s*\)/)
145 die "Misplaced \@REQ" unless $state == 1;
146 # start a new request
149 print SERVER_PROT
"struct ${name}_request\n{\n";
150 print SERVER_PROT
" struct request_header __header;\n";
157 die "Misplaced \@REPLY" unless $state == 2;
158 print SERVER_PROT
"};\n";
159 print SERVER_PROT
"struct ${name}_reply\n{\n";
160 print SERVER_PROT
" struct reply_header __header;\n";
167 die "Misplaced \@END" unless ($state == 2 || $state == 3);
168 print SERVER_PROT
"};\n";
170 if ($state == 2) # build dummy reply struct
172 print SERVER_PROT
"struct ${name}_reply\n{\n";
173 print SERVER_PROT
" struct reply_header __header;\n";
174 print SERVER_PROT
"};\n";
177 # got a complete request
178 push @requests, $name;
179 &DO_DUMP_FUNC
( $name, "request", @in_struct);
180 if ($#out_struct >= 0)
183 &DO_DUMP_FUNC
( $name, "reply", @out_struct);
191 # skip empty lines (but keep them in output file)
194 print SERVER_PROT
"\n";
198 if (/^\s*VARARG\((\w+),(\w+),(\w+)\)/)
201 $type = "dump_varargs_" . $2 . "( min(cur_size,req->" . $3 . ") )";
202 s!(VARARG\(.*\)\s*;)!/* $1 */!;
204 elsif (/^\s*VARARG\((\w+),(\w+)\)/)
207 $type = "dump_varargs_" . $2 . "( cur_size )";
208 s!(VARARG\(.*\)\s*;)!/* $1 */!;
210 elsif (/^\s*(\w+\**(\s+\w+\**)*)\s+(\w+);/)
214 die "Unrecognized type $type" unless defined($formats{$type});
218 die "Unrecognized syntax $_";
220 if ($state == 2) { push @in_struct, $type, $var; }
221 if ($state == 3) { push @out_struct, $type, $var; }
224 # Pass it through into the output file
225 print SERVER_PROT
$_ . "\n";
230 ### Generate a dumping function
236 push @trace_lines, "static void dump_${name}_$req( const struct ${name}_$req *req )\n{\n";
241 if (defined($formats{$type}))
243 if ($formats{$type} =~ /^&(.*)/)
246 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
247 push @trace_lines, " $func( &req->$var );\n";
248 push @trace_lines, " fprintf( stderr, \",\" );\n" if ($#_ > 0);
252 push @trace_lines, " fprintf( stderr, \" $var=$formats{$type}";
253 push @trace_lines, "," if ($#_ > 0);
254 push @trace_lines, "\", ";
255 push @trace_lines, "req->$var );\n";
258 else # must be some varargs format
261 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
262 push @trace_lines, " $func;\n";
263 push @trace_lines, " fputc( ',', stderr );\n" if ($#_ > 0);
266 push @trace_lines, "}\n\n";
269 ### Retrieve the server protocol version from the existing server_protocol.h file
271 sub GET_PROTOCOL_VERSION
274 open SERVER_PROT
, "include/wine/server_protocol.h" or return 0;
275 while (<SERVER_PROT
>)
277 if (/^\#define SERVER_PROTOCOL_VERSION (\d+)/) { $protocol = $1; last; }
283 ### Replace the contents of a file between ### make_requests ### marks
290 open(FILE
,$name) or die "Can't open $name";
294 last if /\#\#\# make_requests begin \#\#\#/;
296 push @lines, "\n", @data;
299 if (/\#\#\# make_requests end \#\#\#/) { push @lines, "\n", $_; last; }
302 open(FILE
,">$name") or die "Can't modify $name";