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
13 "unsigned char" => "%02x",
14 "unsigned int" => "%08x",
17 "path_t" => "&dump_path_t",
18 "char[1]" => "&dump_string",
19 "WCHAR[1]" => "&dump_unicode_string"
25 open(SERVER,"include/server.h") or die "Can't open include/server.h";
27 ### Parse server.h to find request/reply structure definitions
30 my $protocol = 0; # server protocol version
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
105 my ($dir, $type, $var);
110 if (/REQUEST_HEADER/)
112 die "Duplicated header" if $got_header;
113 die "Header must be first" if ($#in_struct != -1 || $#out_struct != -1);
117 if (/^\s*(IN|OUT)\s*VARARG\((\w+),(\w+)\)/)
121 $type = "&dump_varargs_" . $3;
123 elsif (/^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/)
126 $type = $2 . ($5 || "");
128 die "Unrecognized type $type" unless (defined($formats{$type}) || $5);
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)
143 &DO_DUMP_FUNC( $name, "reply", @out_struct);
147 ### Generate a dumping function
153 push @trace_lines, "static void dump_${name}_$req( const struct ${name}_request *req )\n{\n";
158 if (defined($formats{$type}))
160 if ($formats{$type} =~ /^&(.*)/)
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);
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 =~ /^&(.*)/)
181 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
182 push @trace_lines, " $func( get_req_data(req), get_req_data_size(req) );\n";
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
201 open(FILE,$name) or die "Can't open $name";
205 last if /\#\#\# make_requests begin \#\#\#/;
207 push @lines, "\n", @data;
210 if (/\#\#\# make_requests end \#\#\#/) { push @lines, "\n", $_; last; }
213 open(FILE,">$name") or die "Can't modify $name";