Direct3D header update.
[wine.git] / tools / make_requests
blobb0a77d7b45560c0f2a29e51a6c473b5d6c0f2dc0
1 #! /usr/bin/perl -w
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
9 %formats =
11 "int" => "%d",
12 "char" => "%c",
13 "unsigned char" => "%02x",
14 "unsigned int" => "%08x",
15 "void*" => "%p",
16 "time_t" => "%ld",
17 "handle_t" => "%d",
20 my @requests = ();
21 my %replies = ();
23 open(SERVER,"include/server.h") or die "Can't open include/server.h";
25 ### Parse server.h to find request/reply structure definitions
27 my @trace_lines = ();
28 my $protocol = 0; # server protocol version
30 while (<SERVER>)
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
95 sub DO_REQUEST
97 my $name = shift;
98 my @in_struct = ();
99 my @out_struct = ();
100 my $got_header = 0;
101 while (<SERVER>)
103 my ($dir, $type, $var);
104 last if /^};$/;
105 next if /^{$/;
106 s!/\*.*\*/!!g;
107 next if /^\s*$/;
108 if (/REQUEST_HEADER/)
110 die "Duplicated header" if $got_header;
111 die "Header must be first" if ($#in_struct != -1 || $#out_struct != -1);
112 $got_header++;
113 next;
115 if (/^\s*(IN|OUT)\s*VARARG\((\w+),(\w+)\)/)
117 $dir = $1;
118 $var = $2;
119 $type = "&dump_varargs_" . $3;
121 elsif (/^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/)
123 $dir = $1;
124 $type = $2 . ($5 || "");
125 $var = $4;
126 die "Unrecognized type $type" unless (defined($formats{$type}) || $5);
128 else
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)
140 $replies{$name} = 1;
141 &DO_DUMP_FUNC( $name, "reply", @out_struct);
145 ### Generate a dumping function
147 sub DO_DUMP_FUNC
149 my $name = shift;
150 my $req = shift;
151 push @trace_lines, "static void dump_${name}_$req( const struct ${name}_request *req )\n{\n";
152 while ($#_ >= 0)
154 my $type = shift;
155 my $var = shift;
156 if (defined($formats{$type}))
158 if ($formats{$type} =~ /^&(.*)/)
160 my $func = $1;
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);
166 else
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 =~ /^&(.*)/)
178 my $func = $1;
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);
183 else
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
195 sub REPLACE_IN_FILE
197 my $name = shift;
198 my @data = @_;
199 my @lines = ();
200 open(FILE,$name) or die "Can't open $name";
201 while (<FILE>)
203 push @lines, $_;
204 last if /\#\#\# make_requests begin \#\#\#/;
206 push @lines, "\n", @data;
207 while (<FILE>)
209 if (/\#\#\# make_requests end \#\#\#/) { push @lines, "\n", $_; last; }
211 push @lines, <FILE>;
212 open(FILE,">$name") or die "Can't modify $name";
213 print FILE @lines;
214 close(FILE);