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 int" => "%08x",
17 "char[1]" => "\\\"%s\\\""
23 open(SERVER
,"include/server.h") or die "Can't open include/server.h";
25 ### Parse server.h to find request/reply structure definitions
31 if (/^struct +(\w+)_request/) { &DO_REQUEST
($1); }
34 ### Output the dumping function tables
36 push @trace_lines, "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n";
37 foreach $req (@requests)
39 push @trace_lines, " (dump_func)dump_${req}_request,\n";
41 push @trace_lines, "};\n\n";
43 push @trace_lines, "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n";
44 foreach $req (@requests)
46 push @trace_lines, " (dump_func)", $replies{$req} ?
"dump_${req}_reply,\n" : "0,\n";
48 push @trace_lines, "};\n\n";
50 push @trace_lines, "static const char * const req_names[REQ_NB_REQUESTS] = {\n";
51 foreach $req (@requests)
53 push @trace_lines, " \"$req\",\n";
55 push @trace_lines, "};\n";
57 REPLACE_IN_FILE
( "server/trace.c", @trace_lines );
59 ### Replace the request list in server.h by the new values
61 my @server_lines = ();
63 push @server_lines, "enum request\n{\n";
64 foreach $req (@requests) { push @server_lines, " REQ_\U$req,\n"; }
65 push @server_lines, " REQ_NB_REQUESTS\n};\n";
67 REPLACE_IN_FILE
( "include/server.h", @server_lines );
69 ### Output the request handlers list
71 my @request_lines = ();
73 foreach $req (@requests) { push @request_lines, "DECL_HANDLER($req);\n"; }
74 push @request_lines, "\n#ifdef WANT_REQUEST_HANDLERS\n\n";
75 push @request_lines, "static const struct handler {\n";
76 push @request_lines, " void (*handler)( void *req, int fd );\n";
77 push @request_lines, " unsigned int min_size;\n";
78 push @request_lines, "} req_handlers[REQ_NB_REQUESTS] = {\n";
79 foreach $req (@requests)
81 push @request_lines, " { (void(*)())req_$req, sizeof(struct ${req}_request) },\n";
83 push @request_lines, "};\n#endif /* WANT_REQUEST_HANDLERS */\n";
85 REPLACE_IN_FILE
( "server/request.h", @request_lines );
87 ### Handle a request structure definition
96 my ($dir, $type, $var);
101 /^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/ or die "Unrecognized syntax $_";
103 $type = $2 . ($5 || "");
105 die "Unrecognized type $type" unless (defined($formats{$type}) || $5);
106 if ($dir =~ /IN/) { push @in_struct, $type, $var; }
107 if ($dir =~ /OUT/) { push @out_struct, $type, $var; }
109 push @requests, $name;
110 &DO_DUMP_FUNC
( $name, "request", @in_struct);
111 if ($#out_struct >= 0)
114 &DO_DUMP_FUNC
( $name, "reply", @out_struct);
118 ### Generate a dumping function
124 push @trace_lines, "static void dump_${name}_$req( struct ${name}_request *req )\n{\n";
129 if (defined($formats{$type}))
131 push @trace_lines, " fprintf( stderr, \" $var=$formats{$type}";
132 push @trace_lines, "," if ($#_ > 0);
133 push @trace_lines, "\", ";
134 push @trace_lines, "req->$var );\n";
136 else # must be some varargs format
138 push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
139 push @trace_lines, " dump_varargs_${name}( req );\n";
142 push @trace_lines, "}\n\n";
145 ### Replace the contents of a file between ### make_requests ### marks
152 open(FILE
,$name) or die "Can't open $name";
156 last if /\#\#\# make_requests begin \#\#\#/;
158 push @lines, "\n", @data;
161 if (/\#\#\# make_requests end \#\#\#/) { push @lines, "\n", $_; last; }
164 open(FILE
,">$name") or die "Can't modify $name";