IPaddress common control implementation. First try; needs more work to
[wine/multimedia.git] / tools / make_requests
blobf02bd43f604528d7184338bf4a72ed7d5514d9b6
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 "unsigned int" => "%08x",
13 "void*" => "%p"
16 my @requests = ();
17 my %replies = ();
19 open(SERVER,"include/server.h") or die "Can't open include/server.h";
20 open(TRACE,">server/trace.c") or die "Can't create server/trace.c";
21 open(REQUESTS,">include/server/request.h") or die "Can't create include/server/request.h";
23 ### Generate the header
25 print TRACE <<EOF;
26 /* File generated automatically by $0; DO NOT EDIT!! */
28 #include <stdio.h>
29 #include <sys/types.h>
30 #include <sys/uio.h>
31 #include "server.h"
32 #include "server/thread.h"
33 EOF
35 ### Parse server.h to find request/reply structure definitions
37 while (<SERVER>)
39 if (/^struct +(\w+)_request/) { &DO_REQUEST($1); }
40 if (/^struct +(\w+)_reply/) { &DO_REPLY($1); }
43 ### Output the dumping function tables
45 print TRACE<<EOF;
47 struct dumper
49 void (*dump_req)();
50 void (*dump_reply)();
51 unsigned int size;
54 static const struct dumper dumpers[REQ_NB_REQUESTS] =
56 EOF
58 foreach $req (@requests)
60 $request = $req . "_request";
61 $reply = $replies{$req} ? "dump_${req}_reply" : "0";
62 print TRACE " { (void(*)())dump_$request,\n";
63 print TRACE " (void(*)())$reply,\n";
64 print TRACE " sizeof(struct $request) },\n";
67 print TRACE <<EOF;
70 static const char * const req_names[REQ_NB_REQUESTS] =
72 EOF
73 foreach $req (@requests)
75 print TRACE " \"$req\",\n";
78 ### Output the tracing functions
80 print TRACE <<EOF;
83 void trace_request( enum request req, void *data, int len, int fd )
85 current->last_req = req;
86 printf( "%08x: %s(", (unsigned int)current, req_names[req] );
87 dumpers[req].dump_req( data );
88 if (len > dumpers[req].size)
90 unsigned char *ptr = (unsigned char *)data + dumpers[req].size;
91 len -= dumpers[req].size;
92 while (len--) printf( ", %02x", *ptr++ );
94 if (fd != -1) printf( " ) fd=%d\\n", fd );
95 else printf( " )\\n" );
98 void trace_timeout(void)
100 printf( "%08x: *timeout*\\n", (unsigned int)current );
103 void trace_kill( int exit_code )
105 printf( "%08x: *killed* exit_code=%d\\n",
106 (unsigned int)current, exit_code );
109 void trace_reply( struct thread *thread, int type, int pass_fd,
110 struct iovec *vec, int veclen )
112 if (!thread) return;
113 printf( "%08x: %s() = %d",
114 (unsigned int)thread, req_names[thread->last_req], type );
115 if (veclen)
117 printf( " {" );
118 if (dumpers[thread->last_req].dump_reply)
120 dumpers[thread->last_req].dump_reply( vec->iov_base );
121 vec++;
122 veclen--;
124 for (; veclen; veclen--, vec++)
126 unsigned char *ptr = vec->iov_base;
127 int len = vec->iov_len;
128 while (len--) printf( ", %02x", *ptr++ );
130 printf( " }" );
132 if (pass_fd != -1) printf( " fd=%d\\n", pass_fd );
133 else printf( "\\n" );
137 ### Output the requests list
139 print REQUESTS <<EOF;
140 /* File generated automatically by $0; DO NOT EDIT!! */
142 #ifndef __WINE_SERVER_REQUEST_H
143 #define __WINE_SERVER_REQUEST_H
145 enum request
149 foreach $req (@requests)
151 print REQUESTS " REQ_\U$req,\n";
154 print REQUESTS <<EOF;
155 REQ_NB_REQUESTS
158 #ifdef WANT_REQUEST_HANDLERS
160 #define DECL_HANDLER(name) \\
161 static void req_##name( struct name##_request *req, void *data, int len, int fd )
165 foreach $req (@requests) { print REQUESTS "DECL_HANDLER($req);\n"; }
167 print REQUESTS <<EOF;
169 static const struct handler {
170 void (*handler)();
171 unsigned int min_size;
172 } req_handlers[REQ_NB_REQUESTS] = {
175 foreach $req (@requests)
177 print REQUESTS " { (void(*)())req_$req, sizeof(struct ${req}_request) },\n";
180 print REQUESTS <<EOF;
182 #endif /* WANT_REQUEST_HANDLERS */
184 #endif /* __WINE_SERVER_REQUEST_H */
187 ### Handle a request structure definition
189 sub DO_REQUEST
191 my $name = shift;
192 my @struct = ();
193 while (<SERVER>)
195 last if /^};$/;
196 next if /^{$/;
197 s!/\*.*\*/!!g;
198 next if /^\s*$/;
199 / *(\w+\**( +\w+\**)*) +(\w+);/ or die "Unrecognized syntax $_";
200 my $type = $1;
201 my $var = $3;
202 die "Unrecognized type $type" unless defined($formats{$type});
203 push @struct, $type, $var;
205 push @requests, $name;
206 &DO_DUMP_FUNC( $name . "_request",@struct);
209 ### Handle a reply structure definition
211 sub DO_REPLY
213 my $name = shift;
214 my @struct = ();
215 while (<SERVER>)
217 last if /^};$/;
218 next if /^{$/;
219 s!/\*.*\*/!!g;
220 next if /^\s*$/;
221 / *(\w+\**( +\w+\**)*) +(\w+);/ or die "Unrecognized syntax $_";
222 my $type = $1;
223 my $var = $3;
224 die "Unrecognized type $type" unless defined($formats{$type});
225 push @struct, $type, $var;
227 $replies{$name} = 1;
228 &DO_DUMP_FUNC( $name . "_reply" ,@struct);
231 ### Generate a dumping function
233 sub DO_DUMP_FUNC
235 my $name = shift;
236 print TRACE "\nstatic void dump_$name( struct $name *req )\n{\n";
237 while ($#_ >= 0)
239 my $type = shift;
240 my $var = shift;
241 print TRACE " printf( \" $var=$formats{$type}";
242 print TRACE "," if ($#_ > 0);
243 print TRACE "\", req->$var );\n";
245 print TRACE "}\n";