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",
21 "user_handle_t" => "%08x",
22 "rectangle_t" => "&dump_rectangle",
30 # Get the server protocol version
31 my $protocol = &GET_PROTOCOL_VERSION;
33 ### Create server_protocol.h and print header
35 open SERVER_PROT, ">include/wine/server_protocol.h" or die "Cannot create include/wine/server_protocol.h";
36 print SERVER_PROT "/*\n * Wine server protocol definitions\n *\n";
37 print SERVER_PROT " * This file is automatically generated; DO NO EDIT!\n";
38 print SERVER_PROT " * Edit server/protocol.def instead and re-run tools/make_requests\n";
39 print SERVER_PROT " */\n\n";
40 print SERVER_PROT "#ifndef __WINE_WINE_SERVER_PROTOCOL_H\n";
41 print SERVER_PROT "#define __WINE_WINE_SERVER_PROTOCOL_H\n";
43 ### Parse requests to find request/reply structure definitions
47 ### Build the request list
49 print SERVER_PROT "\n\nenum request\n{\n";
50 foreach $req (@requests) { print SERVER_PROT " REQ_$req,\n"; }
51 print SERVER_PROT " REQ_NB_REQUESTS\n};\n\n";
52 print SERVER_PROT "union generic_request\n{\n";
53 print SERVER_PROT " struct request_max_size max_size;\n";
54 print SERVER_PROT " struct request_header header;\n";
55 foreach $req (@requests) { print SERVER_PROT " struct ${req}_request $req;\n"; }
56 print SERVER_PROT "};\n\n";
57 printf SERVER_PROT "#define SERVER_PROTOCOL_VERSION %d\n\n", $protocol + 1;
58 print SERVER_PROT "#endif /* __WINE_WINE_SERVER_PROTOCOL_H */\n";
61 ### Output the dumping function tables
63 push @trace_lines, "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n";
64 foreach $req (@requests)
66 push @trace_lines, " (dump_func)dump_${req}_request,\n";
68 push @trace_lines, "};\n\n";
70 push @trace_lines, "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n";
71 foreach $req (@requests)
73 push @trace_lines, " (dump_func)", $replies{$req} ? "dump_${req}_reply,\n" : "0,\n";
75 push @trace_lines, "};\n\n";
77 push @trace_lines, "static const char * const req_names[REQ_NB_REQUESTS] = {\n";
78 foreach $req (@requests)
80 push @trace_lines, " \"$req\",\n";
82 push @trace_lines, "};\n";
84 REPLACE_IN_FILE( "server/trace.c", @trace_lines );
86 ### Output the request handlers list
88 my @request_lines = ();
90 foreach $req (@requests) { push @request_lines, "DECL_HANDLER($req);\n"; }
91 push @request_lines, "\n#ifdef WANT_REQUEST_HANDLERS\n\n";
92 push @request_lines, "typedef void (*req_handler)( void *req );\n";
93 push @request_lines, "static const req_handler req_handlers[REQ_NB_REQUESTS] =\n{\n";
94 foreach $req (@requests)
96 push @request_lines, " (req_handler)req_$req,\n";
98 push @request_lines, "};\n#endif /* WANT_REQUEST_HANDLERS */\n";
100 REPLACE_IN_FILE( "server/request.h", @request_lines );
102 ### Parse the request definitions
106 # states: 0 = header 1 = declarations 2 = inside @REQ 3 = inside @REPLY
112 open(PROTOCOL,"server/protocol.def") or die "Can't open server/protocol.def";
119 # strip white space at end of line
124 die "Misplaced \@HEADER" unless $state == 0;
129 # ignore everything while in state 0
132 if (/^\@REQ\(\s*(\w+)\s*\)/)
135 die "Misplaced \@REQ" unless $state == 1;
136 # start a new request
139 print SERVER_PROT "struct ${name}_request\n{\n";
140 print SERVER_PROT " struct request_header __header;\n";
147 die "Misplaced \@REPLY" unless $state == 2;
154 die "Misplaced \@END" unless ($state == 2 || $state == 3);
155 print SERVER_PROT "};\n";
157 # got a complete request
158 push @requests, $name;
159 &DO_DUMP_FUNC( $name, "request", @in_struct);
160 if ($#out_struct >= 0)
163 &DO_DUMP_FUNC( $name, "reply", @out_struct);
171 # skip empty lines (but keep them in output file)
174 print SERVER_PROT "\n";
178 if (/^\s*VARARG\((\w+),(\w+)\)/)
181 $type = "&dump_varargs_" . $2;
182 s!(VARARG\(.*\)\s*;)!/* $1 */!;
184 elsif (/^\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/)
186 $type = $1 . ($4 || "");
188 die "Unrecognized type $type" unless (defined($formats{$type}) || $4);
192 die "Unrecognized syntax $_";
194 if ($state == 2) { push @in_struct, $type, $var; }
195 if ($state == 3) { push @out_struct, $type, $var; }
198 # Pass it through into the output file
199 print SERVER_PROT $_ . "\n";
204 ### Generate a dumping function
210 push @trace_lines, "static void dump_${name}_$req( const struct ${name}_request *req )\n{\n";
215 if (defined($formats{$type}))
217 if ($formats{$type} =~ /^&(.*)/)
220 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
221 if ($type =~ /[1]/) { push @trace_lines, " $func( req, req->$var );\n"; }
222 else { push @trace_lines, " $func( req, &req->$var );\n"; }
223 push @trace_lines, " fprintf( stderr, \",\" );\n" if ($#_ > 0);
227 push @trace_lines, " fprintf( stderr, \" $var=$formats{$type}";
228 push @trace_lines, "," if ($#_ > 0);
229 push @trace_lines, "\", ";
230 push @trace_lines, "req->$var );\n";
233 else # must be some varargs format
235 if ($type =~ /^&(.*)/)
238 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
239 push @trace_lines, " cur_pos += $func( req );\n";
240 push @trace_lines, " fputc( ',', stderr );\n" if ($#_ > 0);
244 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
245 push @trace_lines, " dump_varargs_${name}_${req}( req );\n";
249 push @trace_lines, "}\n\n";
252 ### Retrieve the server protocol version from the existing server_protocol.h file
254 sub GET_PROTOCOL_VERSION
257 open SERVER_PROT, "include/wine/server_protocol.h" or return 0;
258 while (<SERVER_PROT>)
260 if (/^\#define SERVER_PROTOCOL_VERSION (\d+)/) { $protocol = $1; last; }
266 ### Replace the contents of a file between ### make_requests ### marks
273 open(FILE,$name) or die "Can't open $name";
277 last if /\#\#\# make_requests begin \#\#\#/;
279 push @lines, "\n", @data;
282 if (/\#\#\# make_requests end \#\#\#/) { push @lines, "\n", $_; last; }
285 open(FILE,">$name") or die "Can't modify $name";