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",
23 open(SERVER
,"include/server.h") or die "Can't open include/server.h";
25 ### Parse server.h to find request/reply structure definitions
28 my $protocol = 0; # server protocol version
32 if (/^struct +(\w+)_request/) { &DO_REQUEST
($1); }
33 if (/^\#define SERVER_PROTOCOL_VERSION (\d+)/) { $protocol = $1 + 1; }
36 ### Output the dumping function tables
38 push @trace_lines, "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n";
39 foreach $req (@requests)
41 push @trace_lines, " (dump_func)dump_${req}_request,\n";
43 push @trace_lines, "};\n\n";
45 push @trace_lines, "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n";
46 foreach $req (@requests)
48 push @trace_lines, " (dump_func)", $replies{$req} ?
"dump_${req}_reply,\n" : "0,\n";
50 push @trace_lines, "};\n\n";
52 push @trace_lines, "static const char * const req_names[REQ_NB_REQUESTS] = {\n";
53 foreach $req (@requests)
55 push @trace_lines, " \"$req\",\n";
57 push @trace_lines, "};\n";
59 REPLACE_IN_FILE
( "server/trace.c", @trace_lines );
61 ### Replace the request list in server.h by the new values
63 my @server_lines = ();
65 push @server_lines, "enum request\n{\n";
66 foreach $req (@requests) { push @server_lines, " REQ_$req,\n"; }
67 push @server_lines, " REQ_NB_REQUESTS\n};\n\n";
68 push @server_lines, "union generic_request\n{\n";
69 push @server_lines, " struct request_max_size max_size;\n";
70 push @server_lines, " struct request_header header;\n";
71 foreach $req (@requests) { push @server_lines, " struct ${req}_request $req;\n"; }
72 push @server_lines, "};\n\n";
73 push @server_lines, "#define SERVER_PROTOCOL_VERSION $protocol\n";
75 REPLACE_IN_FILE
( "include/server.h", @server_lines );
77 ### Output the request handlers list
79 my @request_lines = ();
81 foreach $req (@requests) { push @request_lines, "DECL_HANDLER($req);\n"; }
82 push @request_lines, "\n#ifdef WANT_REQUEST_HANDLERS\n\n";
83 push @request_lines, "typedef void (*req_handler)( void *req );\n";
84 push @request_lines, "static const req_handler req_handlers[REQ_NB_REQUESTS] =\n{\n";
85 foreach $req (@requests)
87 push @request_lines, " (req_handler)req_$req,\n";
89 push @request_lines, "};\n#endif /* WANT_REQUEST_HANDLERS */\n";
91 REPLACE_IN_FILE
( "server/request.h", @request_lines );
93 ### Handle a request structure definition
103 my ($dir, $type, $var);
108 if (/REQUEST_HEADER/)
110 die "Duplicated header" if $got_header;
111 die "Header must be first" if ($#in_struct != -1 || $#out_struct != -1);
115 if (/^\s*(IN|OUT)\s*VARARG\((\w+),(\w+)\)/)
119 $type = "&dump_varargs_" . $3;
121 elsif (/^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/)
124 $type = $2 . ($5 || "");
126 die "Unrecognized type $type" unless (defined($formats{$type}) || $5);
130 die "Unrecognized syntax $_";
132 if ($dir =~ /IN/) { push @in_struct, $type, $var; }
133 if ($dir =~ /OUT/) { push @out_struct, $type, $var; }
135 die "Missing header" unless $got_header;
136 push @requests, $name;
137 &DO_DUMP_FUNC
( $name, "request", @in_struct);
138 if ($#out_struct >= 0)
141 &DO_DUMP_FUNC
( $name, "reply", @out_struct);
145 ### Generate a dumping function
151 push @trace_lines, "static void dump_${name}_$req( const struct ${name}_request *req )\n{\n";
156 if (defined($formats{$type}))
158 if ($formats{$type} =~ /^&(.*)/)
161 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
162 if ($type =~ /[1]/) { push @trace_lines, " $func( req, req->$var );\n"; }
163 else { push @trace_lines, " $func( req, &req->$var );\n"; }
164 push @trace_lines, " fprintf( stderr, \",\" );\n" if ($#_ > 0);
168 push @trace_lines, " fprintf( stderr, \" $var=$formats{$type}";
169 push @trace_lines, "," if ($#_ > 0);
170 push @trace_lines, "\", ";
171 push @trace_lines, "req->$var );\n";
174 else # must be some varargs format
176 if ($type =~ /^&(.*)/)
179 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
180 push @trace_lines, " cur_pos += $func( req );\n";
181 push @trace_lines, " fputc( ',', stderr );\n" if ($#_ > 0);
185 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
186 push @trace_lines, " dump_varargs_${name}_${req}( req );\n";
190 push @trace_lines, "}\n\n";
193 ### Replace the contents of a file between ### make_requests ### marks
200 open(FILE
,$name) or die "Can't open $name";
204 last if /\#\#\# make_requests begin \#\#\#/;
206 push @lines, "\n", @data;
209 if (/\#\#\# make_requests end \#\#\#/) { push @lines, "\n", $_; last; }
212 open(FILE
,">$name") or die "Can't modify $name";