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 "EXCEPTION_RECORD" => "&dump_exc_record",
22 "char[1]" => "\\\"%s\\\"",
23 "WCHAR[1]" => "&dump_unicode_string"
29 open(SERVER
,"include/server.h") or die "Can't open include/server.h";
31 ### Parse server.h to find request/reply structure definitions
34 my $protocol = 0; # server protocol version
38 if (/^struct +(\w+)_request/) { &DO_REQUEST
($1); }
39 if (/^\#define SERVER_PROTOCOL_VERSION (\d+)/) { $protocol = $1 + 1; }
42 ### Output the dumping function tables
44 push @trace_lines, "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n";
45 foreach $req (@requests)
47 push @trace_lines, " (dump_func)dump_${req}_request,\n";
49 push @trace_lines, "};\n\n";
51 push @trace_lines, "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n";
52 foreach $req (@requests)
54 push @trace_lines, " (dump_func)", $replies{$req} ?
"dump_${req}_reply,\n" : "0,\n";
56 push @trace_lines, "};\n\n";
58 push @trace_lines, "static const char * const req_names[REQ_NB_REQUESTS] = {\n";
59 foreach $req (@requests)
61 push @trace_lines, " \"$req\",\n";
63 push @trace_lines, "};\n";
65 REPLACE_IN_FILE
( "server/trace.c", @trace_lines );
67 ### Replace the request list in server.h by the new values
69 my @server_lines = ();
71 push @server_lines, "enum request\n{\n";
72 foreach $req (@requests) { push @server_lines, " REQ_\U$req,\n"; }
73 push @server_lines, " REQ_NB_REQUESTS\n};\n";
74 push @server_lines, "\n#define SERVER_PROTOCOL_VERSION $protocol\n";
76 REPLACE_IN_FILE
( "include/server.h", @server_lines );
78 ### Output the request handlers list
80 my @request_lines = ();
82 foreach $req (@requests) { push @request_lines, "DECL_HANDLER($req);\n"; }
83 push @request_lines, "\n#ifdef WANT_REQUEST_HANDLERS\n\n";
84 push @request_lines, "typedef void (*req_handler)( void *req );\n";
85 push @request_lines, "static const req_handler req_handlers[REQ_NB_REQUESTS] =\n{\n";
86 foreach $req (@requests)
88 push @request_lines, " (req_handler)req_$req,\n";
90 push @request_lines, "};\n#endif /* WANT_REQUEST_HANDLERS */\n";
92 REPLACE_IN_FILE
( "server/request.h", @request_lines );
94 ### Handle a request structure definition
103 my ($dir, $type, $var);
108 /^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/ or die "Unrecognized syntax $_";
110 $type = $2 . ($5 || "");
112 die "Unrecognized type $type" unless (defined($formats{$type}) || $5);
113 if ($dir =~ /IN/) { push @in_struct, $type, $var; }
114 if ($dir =~ /OUT/) { push @out_struct, $type, $var; }
116 push @requests, $name;
117 &DO_DUMP_FUNC
( $name, "request", @in_struct);
118 if ($#out_struct >= 0)
121 &DO_DUMP_FUNC
( $name, "reply", @out_struct);
125 ### Generate a dumping function
131 push @trace_lines, "static void dump_${name}_$req( const struct ${name}_request *req )\n{\n";
136 if (defined($formats{$type}))
138 if ($formats{$type} =~ /^&(.*)/)
141 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
142 if ($type =~ /[1]/) { push @trace_lines, " $func( req->$var );\n"; }
143 else { push @trace_lines, " $func( &req->$var );\n"; }
144 push @trace_lines, " fprintf( stderr, \",\" );\n" if ($#_ > 0);
148 push @trace_lines, " fprintf( stderr, \" $var=$formats{$type}";
149 push @trace_lines, "," if ($#_ > 0);
150 push @trace_lines, "\", ";
151 push @trace_lines, "req->$var );\n";
154 else # must be some varargs format
156 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
157 push @trace_lines, " dump_varargs_${name}_${req}( req );\n";
160 push @trace_lines, "}\n\n";
163 ### Replace the contents of a file between ### make_requests ### marks
170 open(FILE
,$name) or die "Can't open $name";
174 last if /\#\#\# make_requests begin \#\#\#/;
176 push @lines, "\n", @data;
179 if (/\#\#\# make_requests end \#\#\#/) { push @lines, "\n", $_; last; }
182 open(FILE
,">$name") or die "Can't modify $name";