Fixed allocation of 16x16 icons.
[wine.git] / tools / make_requests
blob8e608ccf52c8c809b1e8e49c1452fbde37f3298d
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 "long" => "%ld",
13 "char" => "%c",
14 "unsigned char" => "%02x",
15 "unsigned int" => "%08x",
16 "void*" => "%p",
17 "time_t" => "%ld",
18 "path_t" => "&dump_path_t",
19 "debug_event_t" => "&dump_debug_event_t",
20 "CONTEXT" => "&dump_context",
21 "char[1]" => "\\\"%s\\\"",
22 "WCHAR[1]" => "&dump_unicode_string"
25 my @requests = ();
26 my %replies = ();
28 open(SERVER,"include/server.h") or die "Can't open include/server.h";
30 ### Parse server.h to find request/reply structure definitions
32 my @trace_lines = ();
34 while (<SERVER>)
36 if (/^struct +(\w+)_request/) { &DO_REQUEST($1); }
39 ### Output the dumping function tables
41 push @trace_lines, "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n";
42 foreach $req (@requests)
44 push @trace_lines, " (dump_func)dump_${req}_request,\n";
46 push @trace_lines, "};\n\n";
48 push @trace_lines, "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n";
49 foreach $req (@requests)
51 push @trace_lines, " (dump_func)", $replies{$req} ? "dump_${req}_reply,\n" : "0,\n";
53 push @trace_lines, "};\n\n";
55 push @trace_lines, "static const char * const req_names[REQ_NB_REQUESTS] = {\n";
56 foreach $req (@requests)
58 push @trace_lines, " \"$req\",\n";
60 push @trace_lines, "};\n";
62 REPLACE_IN_FILE( "server/trace.c", @trace_lines );
64 ### Replace the request list in server.h by the new values
66 my @server_lines = ();
68 push @server_lines, "enum request\n{\n";
69 foreach $req (@requests) { push @server_lines, " REQ_\U$req,\n"; }
70 push @server_lines, " REQ_NB_REQUESTS\n};\n";
72 REPLACE_IN_FILE( "include/server.h", @server_lines );
74 ### Output the request handlers list
76 my @request_lines = ();
78 foreach $req (@requests) { push @request_lines, "DECL_HANDLER($req);\n"; }
79 push @request_lines, "\n#ifdef WANT_REQUEST_HANDLERS\n\n";
80 push @request_lines, "static const struct handler {\n";
81 push @request_lines, " void (*handler)( void *req, int fd );\n";
82 push @request_lines, " unsigned int min_size;\n";
83 push @request_lines, "} req_handlers[REQ_NB_REQUESTS] = {\n";
84 foreach $req (@requests)
86 push @request_lines, " { (void(*)())req_$req, sizeof(struct ${req}_request) },\n";
88 push @request_lines, "};\n#endif /* WANT_REQUEST_HANDLERS */\n";
90 REPLACE_IN_FILE( "server/request.h", @request_lines );
92 ### Handle a request structure definition
94 sub DO_REQUEST
96 my $name = shift;
97 my @in_struct = ();
98 my @out_struct = ();
99 while (<SERVER>)
101 my ($dir, $type, $var);
102 last if /^};$/;
103 next if /^{$/;
104 s!/\*.*\*/!!g;
105 next if /^\s*$/;
106 /^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/ or die "Unrecognized syntax $_";
107 $dir = $1;
108 $type = $2 . ($5 || "");
109 $var = $4;
110 die "Unrecognized type $type" unless (defined($formats{$type}) || $5);
111 if ($dir =~ /IN/) { push @in_struct, $type, $var; }
112 if ($dir =~ /OUT/) { push @out_struct, $type, $var; }
114 push @requests, $name;
115 &DO_DUMP_FUNC( $name, "request", @in_struct);
116 if ($#out_struct >= 0)
118 $replies{$name} = 1;
119 &DO_DUMP_FUNC( $name, "reply", @out_struct);
123 ### Generate a dumping function
125 sub DO_DUMP_FUNC
127 my $name = shift;
128 my $req = shift;
129 push @trace_lines, "static void dump_${name}_$req( const struct ${name}_request *req )\n{\n";
130 while ($#_ >= 0)
132 my $type = shift;
133 my $var = shift;
134 if (defined($formats{$type}))
136 if ($formats{$type} =~ /^&(.*)/)
138 my $func = $1;
139 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
140 if ($type =~ /[1]/) { push @trace_lines, " $func( req->$var );\n"; }
141 else { push @trace_lines, " $func( &req->$var );\n"; }
142 push @trace_lines, " fprintf( stderr, \",\" );\n" if ($#_ > 0);
144 else
146 push @trace_lines, " fprintf( stderr, \" $var=$formats{$type}";
147 push @trace_lines, "," if ($#_ > 0);
148 push @trace_lines, "\", ";
149 push @trace_lines, "req->$var );\n";
152 else # must be some varargs format
154 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
155 push @trace_lines, " dump_varargs_${name}_${req}( req );\n";
158 push @trace_lines, "}\n\n";
161 ### Replace the contents of a file between ### make_requests ### marks
163 sub REPLACE_IN_FILE
165 my $name = shift;
166 my @data = @_;
167 my @lines = ();
168 open(FILE,$name) or die "Can't open $name";
169 while (<FILE>)
171 push @lines, $_;
172 last if /\#\#\# make_requests begin \#\#\#/;
174 push @lines, "\n", @data;
175 while (<FILE>)
177 if (/\#\#\# make_requests end \#\#\#/) { push @lines, "\n", $_; last; }
179 push @lines, <FILE>;
180 open(FILE,">$name") or die "Can't modify $name";
181 print FILE @lines;
182 close(FILE);