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
14 "unsigned char" => "%02x",
15 "unsigned int" => "%08x",
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"
28 open(SERVER
,"include/server.h") or die "Can't open include/server.h";
30 ### Parse server.h to find request/reply structure definitions
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
101 my ($dir, $type, $var);
106 /^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/ or die "Unrecognized syntax $_";
108 $type = $2 . ($5 || "");
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)
119 &DO_DUMP_FUNC
( $name, "reply", @out_struct);
123 ### Generate a dumping function
129 push @trace_lines, "static void dump_${name}_$req( const struct ${name}_request *req )\n{\n";
134 if (defined($formats{$type}))
136 if ($formats{$type} =~ /^&(.*)/)
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);
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
168 open(FILE
,$name) or die "Can't open $name";
172 last if /\#\#\# make_requests begin \#\#\#/;
174 push @lines, "\n", @data;
177 if (/\#\#\# make_requests end \#\#\#/) { push @lines, "\n", $_; last; }
180 open(FILE
,">$name") or die "Can't modify $name";