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
13 "unsigned char" => "%02x",
14 "unsigned short"=> "%04x",
15 "unsigned int" => "%08x",
20 "user_handle_t" => "%08x",
21 "rectangle_t" => "&dump_rectangle",
29 # Get the server protocol version
30 my $protocol = &GET_PROTOCOL_VERSION;
32 ### Create server_protocol.h and print header
34 open SERVER_PROT, ">include/wine/server_protocol.h" or die "Cannot create include/wine/server_protocol.h";
35 print SERVER_PROT "/*\n * Wine server protocol definitions\n *\n";
36 print SERVER_PROT " * This file is automatically generated; DO NO EDIT!\n";
37 print SERVER_PROT " * Edit server/protocol.def instead and re-run tools/make_requests\n";
38 print SERVER_PROT " */\n\n";
39 print SERVER_PROT "#ifndef __WINE_WINE_SERVER_PROTOCOL_H\n";
40 print SERVER_PROT "#define __WINE_WINE_SERVER_PROTOCOL_H\n";
42 ### Parse requests to find request/reply structure definitions
46 ### Build the request list
48 print SERVER_PROT "\n\nenum request\n{\n";
49 foreach $req (@requests) { print SERVER_PROT " REQ_$req,\n"; }
50 print SERVER_PROT " REQ_NB_REQUESTS\n};\n\n";
51 print SERVER_PROT "union generic_request\n{\n";
52 print SERVER_PROT " struct request_max_size max_size;\n";
53 print SERVER_PROT " struct request_header header;\n";
54 foreach $req (@requests) { print SERVER_PROT " struct ${req}_request $req;\n"; }
55 print SERVER_PROT "};\n\n";
56 printf SERVER_PROT "#define SERVER_PROTOCOL_VERSION %d\n\n", $protocol + 1;
57 print SERVER_PROT "#endif /* __WINE_WINE_SERVER_PROTOCOL_H */\n";
60 ### Output the dumping function tables
62 push @trace_lines, "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n";
63 foreach $req (@requests)
65 push @trace_lines, " (dump_func)dump_${req}_request,\n";
67 push @trace_lines, "};\n\n";
69 push @trace_lines, "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n";
70 foreach $req (@requests)
72 push @trace_lines, " (dump_func)", $replies{$req} ? "dump_${req}_reply,\n" : "0,\n";
74 push @trace_lines, "};\n\n";
76 push @trace_lines, "static const char * const req_names[REQ_NB_REQUESTS] = {\n";
77 foreach $req (@requests)
79 push @trace_lines, " \"$req\",\n";
81 push @trace_lines, "};\n";
83 REPLACE_IN_FILE( "server/trace.c", @trace_lines );
85 ### Output the request handlers list
87 my @request_lines = ();
89 foreach $req (@requests) { push @request_lines, "DECL_HANDLER($req);\n"; }
90 push @request_lines, "\n#ifdef WANT_REQUEST_HANDLERS\n\n";
91 push @request_lines, "typedef void (*req_handler)( void *req );\n";
92 push @request_lines, "static const req_handler req_handlers[REQ_NB_REQUESTS] =\n{\n";
93 foreach $req (@requests)
95 push @request_lines, " (req_handler)req_$req,\n";
97 push @request_lines, "};\n#endif /* WANT_REQUEST_HANDLERS */\n";
99 REPLACE_IN_FILE( "server/request.h", @request_lines );
101 ### Parse the request definitions
105 # states: 0 = header 1 = declarations 2 = inside @REQ 3 = inside @REPLY
111 open(PROTOCOL,"server/protocol.def") or die "Can't open server/protocol.def";
118 # strip white space at end of line
123 die "Misplaced \@HEADER" unless $state == 0;
128 # ignore everything while in state 0
131 if (/^\@REQ\(\s*(\w+)\s*\)/)
134 die "Misplaced \@REQ" unless $state == 1;
135 # start a new request
138 print SERVER_PROT "struct ${name}_request\n{\n";
139 print SERVER_PROT " struct request_header __header;\n";
146 die "Misplaced \@REPLY" unless $state == 2;
153 die "Misplaced \@END" unless ($state == 2 || $state == 3);
154 print SERVER_PROT "};\n";
156 # got a complete request
157 push @requests, $name;
158 &DO_DUMP_FUNC( $name, "request", @in_struct);
159 if ($#out_struct >= 0)
162 &DO_DUMP_FUNC( $name, "reply", @out_struct);
170 # skip empty lines (but keep them in output file)
173 print SERVER_PROT "\n";
177 if (/^\s*VARARG\((\w+),(\w+)\)/)
180 $type = "&dump_varargs_" . $2;
181 s!(VARARG\(.*\)\s*;)!/* $1 */!;
183 elsif (/^\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/)
185 $type = $1 . ($4 || "");
187 die "Unrecognized type $type" unless (defined($formats{$type}) || $4);
191 die "Unrecognized syntax $_";
193 if ($state == 2) { push @in_struct, $type, $var; }
194 if ($state == 3) { push @out_struct, $type, $var; }
197 # Pass it through into the output file
198 print SERVER_PROT $_ . "\n";
203 ### Generate a dumping function
209 push @trace_lines, "static void dump_${name}_$req( const struct ${name}_request *req )\n{\n";
214 if (defined($formats{$type}))
216 if ($formats{$type} =~ /^&(.*)/)
219 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
220 if ($type =~ /[1]/) { push @trace_lines, " $func( req, req->$var );\n"; }
221 else { push @trace_lines, " $func( req, &req->$var );\n"; }
222 push @trace_lines, " fprintf( stderr, \",\" );\n" if ($#_ > 0);
226 push @trace_lines, " fprintf( stderr, \" $var=$formats{$type}";
227 push @trace_lines, "," if ($#_ > 0);
228 push @trace_lines, "\", ";
229 push @trace_lines, "req->$var );\n";
232 else # must be some varargs format
234 if ($type =~ /^&(.*)/)
237 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
238 push @trace_lines, " cur_pos += $func( req );\n";
239 push @trace_lines, " fputc( ',', stderr );\n" if ($#_ > 0);
243 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
244 push @trace_lines, " dump_varargs_${name}_${req}( req );\n";
248 push @trace_lines, "}\n\n";
251 ### Retrieve the server protocol version from the existing server_protocol.h file
253 sub GET_PROTOCOL_VERSION
256 open SERVER_PROT, "include/wine/server_protocol.h" or return 0;
257 while (<SERVER_PROT>)
259 if (/^\#define SERVER_PROTOCOL_VERSION (\d+)/) { $protocol = $1; last; }
265 ### Replace the contents of a file between ### make_requests ### marks
272 open(FILE,$name) or die "Can't open $name";
276 last if /\#\#\# make_requests begin \#\#\#/;
278 push @lines, "\n", @data;
281 if (/\#\#\# make_requests end \#\#\#/) { push @lines, "\n", $_; last; }
284 open(FILE,">$name") or die "Can't modify $name";