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 short"=> "%04x",
15 "unsigned int" => "%08x",
24 open(SERVER,"include/server.h") or die "Can't open include/server.h";
26 ### Parse server.h to find request/reply structure definitions
29 my $protocol = 0; # server protocol version
33 if (/^struct +(\w+)_request/) { &DO_REQUEST($1); }
34 if (/^\#define SERVER_PROTOCOL_VERSION (\d+)/) { $protocol = $1 + 1; }
37 ### Output the dumping function tables
39 push @trace_lines, "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n";
40 foreach $req (@requests)
42 push @trace_lines, " (dump_func)dump_${req}_request,\n";
44 push @trace_lines, "};\n\n";
46 push @trace_lines, "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n";
47 foreach $req (@requests)
49 push @trace_lines, " (dump_func)", $replies{$req} ? "dump_${req}_reply,\n" : "0,\n";
51 push @trace_lines, "};\n\n";
53 push @trace_lines, "static const char * const req_names[REQ_NB_REQUESTS] = {\n";
54 foreach $req (@requests)
56 push @trace_lines, " \"$req\",\n";
58 push @trace_lines, "};\n";
60 REPLACE_IN_FILE( "server/trace.c", @trace_lines );
62 ### Replace the request list in server.h by the new values
64 my @server_lines = ();
66 push @server_lines, "enum request\n{\n";
67 foreach $req (@requests) { push @server_lines, " REQ_$req,\n"; }
68 push @server_lines, " REQ_NB_REQUESTS\n};\n\n";
69 push @server_lines, "union generic_request\n{\n";
70 push @server_lines, " struct request_max_size max_size;\n";
71 push @server_lines, " struct request_header header;\n";
72 foreach $req (@requests) { push @server_lines, " struct ${req}_request $req;\n"; }
73 push @server_lines, "};\n\n";
74 push @server_lines, "#define SERVER_PROTOCOL_VERSION $protocol\n";
76 REPLACE_IN_FILE( "include/server.h", @server_lines );
78 ### Output the request handlers list
80 my @request_lines = ();
82 foreach $req (@requests) { push @request_lines, "DECL_HANDLER($req);\n"; }
83 push @request_lines, "\n#ifdef WANT_REQUEST_HANDLERS\n\n";
84 push @request_lines, "typedef void (*req_handler)( void *req );\n";
85 push @request_lines, "static const req_handler req_handlers[REQ_NB_REQUESTS] =\n{\n";
86 foreach $req (@requests)
88 push @request_lines, " (req_handler)req_$req,\n";
90 push @request_lines, "};\n#endif /* WANT_REQUEST_HANDLERS */\n";
92 REPLACE_IN_FILE( "server/request.h", @request_lines );
94 ### Handle a request structure definition
104 my ($dir, $type, $var);
109 if (/REQUEST_HEADER/)
111 die "Duplicated header" if $got_header;
112 die "Header must be first" if ($#in_struct != -1 || $#out_struct != -1);
116 if (/^\s*(IN|OUT)\s*VARARG\((\w+),(\w+)\)/)
120 $type = "&dump_varargs_" . $3;
122 elsif (/^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/)
125 $type = $2 . ($5 || "");
127 die "Unrecognized type $type" unless (defined($formats{$type}) || $5);
131 die "Unrecognized syntax $_";
133 if ($dir =~ /IN/) { push @in_struct, $type, $var; }
134 if ($dir =~ /OUT/) { push @out_struct, $type, $var; }
136 die "Missing header" unless $got_header;
137 push @requests, $name;
138 &DO_DUMP_FUNC( $name, "request", @in_struct);
139 if ($#out_struct >= 0)
142 &DO_DUMP_FUNC( $name, "reply", @out_struct);
146 ### Generate a dumping function
152 push @trace_lines, "static void dump_${name}_$req( const struct ${name}_request *req )\n{\n";
157 if (defined($formats{$type}))
159 if ($formats{$type} =~ /^&(.*)/)
162 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
163 if ($type =~ /[1]/) { push @trace_lines, " $func( req, req->$var );\n"; }
164 else { push @trace_lines, " $func( req, &req->$var );\n"; }
165 push @trace_lines, " fprintf( stderr, \",\" );\n" if ($#_ > 0);
169 push @trace_lines, " fprintf( stderr, \" $var=$formats{$type}";
170 push @trace_lines, "," if ($#_ > 0);
171 push @trace_lines, "\", ";
172 push @trace_lines, "req->$var );\n";
175 else # must be some varargs format
177 if ($type =~ /^&(.*)/)
180 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
181 push @trace_lines, " cur_pos += $func( req );\n";
182 push @trace_lines, " fputc( ',', stderr );\n" if ($#_ > 0);
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";