Add stub for LockFileEx (KERNEL32.513).
[wine.git] / tools / make_requests
blob65245fa2d957da4d9c3615ddc680ac01cf456cb7
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 "unsigned int" => "%08x",
15 "void*" => "%p",
16 "time_t" => "%ld",
17 "char[0]" => "dump_chars",
18 "int[0]" => "dump_ints",
19 "void*[0]" => "dump_ptrs"
22 my @requests = ();
23 my %replies = ();
25 open(SERVER,"include/server.h") or die "Can't open include/server.h";
26 open(TRACE,">server/trace.c") or die "Can't create server/trace.c";
27 open(REQUESTS,">include/server/request.h") or die "Can't create include/server/request.h";
29 ### Generate the header
31 print TRACE <<EOF;
32 /* File generated automatically by $0; DO NOT EDIT!! */
34 #include <stdio.h>
35 #include <sys/types.h>
36 #include <sys/uio.h>
37 #include "server.h"
38 #include "thread.h"
40 static int dump_chars( void *ptr, int len )
42 fprintf( stderr, "\\\"%.*s\\\"", len, (char *)ptr );
43 return len;
46 static int dump_ints( void *ptr, int len )
48 int i;
49 if (!(len /= sizeof(int)))
51 fprintf( stderr, "{}" );
52 return 0;
54 for (i = 0; i < len; i++)
55 fprintf( stderr, "%c%d", i ? ',' : '{', *((int *)ptr + i) );
56 fprintf( stderr, "}" );
57 return len * sizeof(int);
60 static int dump_ptrs( void *ptr, int len )
62 int i;
63 if (!(len /= sizeof(void*)))
65 fprintf( stderr, "{}" );
66 return 0;
68 for (i = 0; i < len; i++)
69 fprintf( stderr, "%c%p", i ? ',' : '{', *((void **)ptr + i) );
70 fprintf( stderr, "}" );
71 return len * sizeof(void*);
73 EOF
75 ### Parse server.h to find request/reply structure definitions
77 while (<SERVER>)
79 if (/^struct +(\w+)_request/) { &DO_REQUEST($1); }
80 if (/^struct +(\w+)_reply/) { &DO_REPLY($1); }
83 ### Output the dumping function tables
85 print TRACE "typedef int (*dump_func)( void *req, int len );\n\n";
86 print TRACE "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n";
87 foreach $req (@requests)
89 print TRACE " (dump_func)dump_${req}_request,\n";
91 print TRACE "};\n\n";
93 print TRACE "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n";
94 foreach $req (@requests)
96 print TRACE " (dump_func)", $replies{$req} ? "dump_${req}_reply,\n" : "0,\n";
98 print TRACE "};\n\n";
100 print TRACE <<EOF;
101 static const char * const req_names[REQ_NB_REQUESTS] =
104 foreach $req (@requests)
106 print TRACE " \"$req\",\n";
109 ### Output the tracing functions
111 print TRACE <<EOF;
114 void trace_request( enum request req, void *data, int len, int fd )
116 int size;
117 current->last_req = req;
118 fprintf( stderr, "%08x: %s(", (unsigned int)current, req_names[req] );
119 size = req_dumpers[req]( data, len );
120 if ((len -= size) > 0)
122 unsigned char *ptr = (unsigned char *)data + size;
123 while (len--) fprintf( stderr, ", %02x", *ptr++ );
125 if (fd != -1) fprintf( stderr, " ) fd=%d\\n", fd );
126 else fprintf( stderr, " )\\n" );
129 void trace_timeout(void)
131 fprintf( stderr, "%08x: *timeout*\\n", (unsigned int)current );
134 void trace_kill( int exit_code )
136 fprintf( stderr,"%08x: *killed* exit_code=%d\\n",
137 (unsigned int)current, exit_code );
140 void trace_reply( struct thread *thread, int type, int pass_fd,
141 struct iovec *vec, int veclen )
143 static char buffer[MAX_MSG_LENGTH];
145 if (!thread) return;
146 fprintf( stderr, "%08x: %s() = %d",
147 (unsigned int)thread, req_names[thread->last_req], type );
148 if (veclen)
150 char *p = buffer;
151 int len;
152 for (; veclen; veclen--, vec++)
154 memcpy( p, vec->iov_base, vec->iov_len );
155 p += vec->iov_len;
157 fprintf( stderr, " {" );
158 len = p - buffer;
159 if (reply_dumpers[thread->last_req])
160 len -= reply_dumpers[thread->last_req]( buffer, len );
161 p -= len;
162 while (len--) fprintf( stderr, ", %02x", *p++ );
163 fprintf( stderr, " }" );
165 if (pass_fd != -1) fprintf( stderr, " fd=%d\\n", pass_fd );
166 else fprintf( stderr, "\\n" );
170 ### Output the requests list
172 print REQUESTS <<EOF;
173 /* File generated automatically by $0; DO NOT EDIT!! */
175 #ifndef __WINE_SERVER_REQUEST_H
176 #define __WINE_SERVER_REQUEST_H
178 enum request
182 foreach $req (@requests)
184 print REQUESTS " REQ_\U$req,\n";
187 print REQUESTS <<EOF;
188 REQ_NB_REQUESTS
191 #ifdef WANT_REQUEST_HANDLERS
195 foreach $req (@requests) { print REQUESTS "DECL_HANDLER($req);\n"; }
197 print REQUESTS <<EOF;
199 static const struct handler {
200 void (*handler)();
201 unsigned int min_size;
202 } req_handlers[REQ_NB_REQUESTS] = {
205 foreach $req (@requests)
207 print REQUESTS " { (void(*)())req_$req, sizeof(struct ${req}_request) },\n";
210 print REQUESTS <<EOF;
212 #endif /* WANT_REQUEST_HANDLERS */
214 #endif /* __WINE_SERVER_REQUEST_H */
217 ### Handle a request structure definition
219 sub DO_REQUEST
221 my $name = shift;
222 my @struct = ();
223 while (<SERVER>)
225 last if /^};$/;
226 next if /^{$/;
227 s!/\*.*\*/!!g;
228 next if /^\s*$/;
229 / *(\w+\**( +\w+\**)*) +(\w+)(\[0\])?;/ or die "Unrecognized syntax $_";
230 my $type = $1 . ($4 || "");
231 my $var = $3;
232 die "Unrecognized type $type" unless defined($formats{$type});
233 push @struct, $type, $var;
235 push @requests, $name;
236 &DO_DUMP_FUNC( $name . "_request",@struct);
239 ### Handle a reply structure definition
241 sub DO_REPLY
243 my $name = shift;
244 my @struct = ();
245 while (<SERVER>)
247 last if /^};$/;
248 next if /^{$/;
249 s!/\*.*\*/!!g;
250 next if /^\s*$/;
251 / *(\w+\**( +\w+\**)*) +(\w+)(\[0\])?;/ or die "Unrecognized syntax $_";
252 my $type = $1 . ($4 || "");
253 my $var = $3;
254 die "Unrecognized type $type" unless defined($formats{$type});
255 push @struct, $type, $var;
257 $replies{$name} = 1;
258 &DO_DUMP_FUNC( $name . "_reply" ,@struct);
261 ### Generate a dumping function
263 sub DO_DUMP_FUNC
265 my $vararg = 0;
266 my $name = shift;
267 print TRACE "\nstatic int dump_$name( struct $name *req, int len )\n{\n";
268 while ($#_ >= 0)
270 my $type = shift;
271 my $var = shift;
272 if ($type =~ /\[0\]$/) # vararg type?
274 $vararg = 1;
275 print TRACE " fprintf( stderr, \" $var=\" );\n";
276 print TRACE " return $formats{$type}( req+1, len - (int)sizeof(*req) ) + sizeof(*req);\n";
278 else
280 print TRACE " fprintf( stderr, \" $var=$formats{$type}";
281 print TRACE "," if ($#_ > 0);
282 print TRACE "\", ";
283 print TRACE "req->$var );\n";
286 print TRACE " return (int)sizeof(*req);\n" unless $vararg;
287 print TRACE "}\n";