Updated bug list by my knowledge of them.
[wine/dcerpc.git] / tools / make_requests
blobd404fa19411cf50c7c2ef1e9802f5bda1cfda637
1 #! /usr/bin/perl -w
3 # Build the server/trace.c and include/server/request.h files
4 # from the contents of include/server.h.
6 # Copyright (C) 1998 Alexandre Julliard
9 %formats =
11 "int" => "%d",
12 "long" => "%ld",
13 "char" => "%c",
14 "char[0]" => "\\\"%.*s\\\"",
15 "unsigned int" => "%08x",
16 "void*" => "%p",
17 "time_t" => "%ld"
20 my @requests = ();
21 my %replies = ();
23 open(SERVER,"include/server.h") or die "Can't open include/server.h";
24 open(TRACE,">server/trace.c") or die "Can't create server/trace.c";
25 open(REQUESTS,">include/server/request.h") or die "Can't create include/server/request.h";
27 ### Generate the header
29 print TRACE <<EOF;
30 /* File generated automatically by $0; DO NOT EDIT!! */
32 #include <stdio.h>
33 #include <sys/types.h>
34 #include <sys/uio.h>
35 #include "server.h"
36 #include "server/thread.h"
37 EOF
39 ### Parse server.h to find request/reply structure definitions
41 while (<SERVER>)
43 if (/^struct +(\w+)_request/) { &DO_REQUEST($1); }
44 if (/^struct +(\w+)_reply/) { &DO_REPLY($1); }
47 ### Output the dumping function tables
49 print TRACE<<EOF;
51 struct dumper
53 int (*dump_req)( void *data, int len );
54 void (*dump_reply)( void *data );
57 static const struct dumper dumpers[REQ_NB_REQUESTS] =
59 EOF
61 foreach $req (@requests)
63 $request = $req . "_request";
64 $reply = $replies{$req} ? "dump_${req}_reply" : "0";
65 print TRACE " { (int(*)(void *,int))dump_$request,\n";
66 print TRACE " (void(*)())$reply },\n";
69 print TRACE <<EOF;
72 static const char * const req_names[REQ_NB_REQUESTS] =
74 EOF
75 foreach $req (@requests)
77 print TRACE " \"$req\",\n";
80 ### Output the tracing functions
82 print TRACE <<EOF;
85 void trace_request( enum request req, void *data, int len, int fd )
87 int size;
88 current->last_req = req;
89 fprintf( stderr, "%08x: %s(", (unsigned int)current, req_names[req] );
90 size = dumpers[req].dump_req( data, len );
91 if ((len -= size) > 0)
93 unsigned char *ptr = (unsigned char *)data + size;
94 while (len--) fprintf( stderr, ", %02x", *ptr++ );
96 if (fd != -1) fprintf( stderr, " ) fd=%d\\n", fd );
97 else fprintf( stderr, " )\\n" );
100 void trace_timeout(void)
102 fprintf( stderr, "%08x: *timeout*\\n", (unsigned int)current );
105 void trace_kill( int exit_code )
107 fprintf( stderr,"%08x: *killed* exit_code=%d\\n",
108 (unsigned int)current, exit_code );
111 void trace_reply( struct thread *thread, int type, int pass_fd,
112 struct iovec *vec, int veclen )
114 if (!thread) return;
115 fprintf( stderr, "%08x: %s() = %d",
116 (unsigned int)thread, req_names[thread->last_req], type );
117 if (veclen)
119 fprintf( stderr, " {" );
120 if (dumpers[thread->last_req].dump_reply)
122 dumpers[thread->last_req].dump_reply( vec->iov_base );
123 vec++;
124 veclen--;
126 for (; veclen; veclen--, vec++)
128 unsigned char *ptr = vec->iov_base;
129 int len = vec->iov_len;
130 while (len--) fprintf( stderr, ", %02x", *ptr++ );
132 fprintf( stderr, " }" );
134 if (pass_fd != -1) fprintf( stderr, " fd=%d\\n", pass_fd );
135 else fprintf( stderr, "\\n" );
139 ### Output the requests list
141 print REQUESTS <<EOF;
142 /* File generated automatically by $0; DO NOT EDIT!! */
144 #ifndef __WINE_SERVER_REQUEST_H
145 #define __WINE_SERVER_REQUEST_H
147 enum request
151 foreach $req (@requests)
153 print REQUESTS " REQ_\U$req,\n";
156 print REQUESTS <<EOF;
157 REQ_NB_REQUESTS
160 #ifdef WANT_REQUEST_HANDLERS
162 #define DECL_HANDLER(name) \\
163 static void req_##name( struct name##_request *req, void *data, int len, int fd )
167 foreach $req (@requests) { print REQUESTS "DECL_HANDLER($req);\n"; }
169 print REQUESTS <<EOF;
171 static const struct handler {
172 void (*handler)();
173 unsigned int min_size;
174 } req_handlers[REQ_NB_REQUESTS] = {
177 foreach $req (@requests)
179 print REQUESTS " { (void(*)())req_$req, sizeof(struct ${req}_request) },\n";
182 print REQUESTS <<EOF;
184 #endif /* WANT_REQUEST_HANDLERS */
186 #endif /* __WINE_SERVER_REQUEST_H */
189 ### Handle a request structure definition
191 sub DO_REQUEST
193 my $name = shift;
194 my @struct = ();
195 while (<SERVER>)
197 last if /^};$/;
198 next if /^{$/;
199 s!/\*.*\*/!!g;
200 next if /^\s*$/;
201 / *(\w+\**( +\w+\**)*) +(\w+)(\[0\])?;/ or die "Unrecognized syntax $_";
202 my $type = $1 . ($4 || "");
203 my $var = $3;
204 die "Unrecognized type $type" unless defined($formats{$type});
205 push @struct, $type, $var;
207 push @requests, $name;
208 &DO_DUMP_FUNC( $name . "_request",@struct);
211 ### Handle a reply structure definition
213 sub DO_REPLY
215 my $name = shift;
216 my @struct = ();
217 while (<SERVER>)
219 last if /^};$/;
220 next if /^{$/;
221 s!/\*.*\*/!!g;
222 next if /^\s*$/;
223 / *(\w+\**( +\w+\**)*) +(\w+);/ or die "Unrecognized syntax $_";
224 my $type = $1;
225 my $var = $3;
226 die "Unrecognized type $type" unless defined($formats{$type});
227 push @struct, $type, $var;
229 $replies{$name} = 1;
230 &DO_DUMP_FUNC( $name . "_reply" ,@struct);
233 ### Generate a dumping function
235 sub DO_DUMP_FUNC
237 my $vararg = 0;
238 my $name = shift;
239 print TRACE "\nstatic int dump_$name( struct $name *req, int len )\n{\n";
240 while ($#_ >= 0)
242 my $type = shift;
243 my $var = shift;
244 print TRACE " fprintf( stderr, \" $var=$formats{$type}";
245 print TRACE "," if ($#_ > 0);
246 print TRACE "\", ";
247 if ($type =~ s/\[0\]$//g) # vararg type?
249 $vararg = 1;
250 print TRACE "len - (int)sizeof(*req), ($type *)(req+1) );\n";
252 else
254 print TRACE "req->$var );\n";
257 print TRACE " return ", $vararg ? "len" : "(int)sizeof(*req)", ";\n}\n";