diff --git a/tools/make_requests b/tools/make_requests index 6563e36b62..dd7f359a59 100755 --- a/tools/make_requests +++ b/tools/make_requests @@ -19,8 +19,9 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +use strict; -%formats = +my %formats = ( "int" => "%d", "short int" => "%d", @@ -46,89 +47,11 @@ my %replies = (); my @trace_lines = (); -# Get the server protocol version -my $protocol = &GET_PROTOCOL_VERSION; -### Create server_protocol.h and print header - -open SERVER_PROT, ">include/wine/server_protocol.h" or die "Cannot create include/wine/server_protocol.h"; -print SERVER_PROT "/*\n * Wine server protocol definitions\n *\n"; -print SERVER_PROT " * This file is automatically generated; DO NO EDIT!\n"; -print SERVER_PROT " * Edit server/protocol.def instead and re-run tools/make_requests\n"; -print SERVER_PROT " */\n\n"; -print SERVER_PROT "#ifndef __WINE_WINE_SERVER_PROTOCOL_H\n"; -print SERVER_PROT "#define __WINE_WINE_SERVER_PROTOCOL_H\n"; - -### Parse requests to find request/reply structure definitions - -&PARSE_REQUESTS; - -### Build the request list and structures - -print SERVER_PROT "\n\nenum request\n{\n"; -foreach $req (@requests) { print SERVER_PROT " REQ_$req,\n"; } -print SERVER_PROT " REQ_NB_REQUESTS\n};\n\n"; - -print SERVER_PROT "union generic_request\n{\n"; -print SERVER_PROT " struct request_max_size max_size;\n"; -print SERVER_PROT " struct request_header request_header;\n"; -foreach $req (@requests) { print SERVER_PROT " struct ${req}_request ${req}_request;\n"; } -print SERVER_PROT "};\n"; - -print SERVER_PROT "union generic_reply\n{\n"; -print SERVER_PROT " struct request_max_size max_size;\n"; -print SERVER_PROT " struct reply_header reply_header;\n"; -foreach $req (@requests) { print SERVER_PROT " struct ${req}_reply ${req}_reply;\n"; } -print SERVER_PROT "};\n\n"; - -printf SERVER_PROT "#define SERVER_PROTOCOL_VERSION %d\n\n", $protocol + 1; -print SERVER_PROT "#endif /* __WINE_WINE_SERVER_PROTOCOL_H */\n"; -close SERVER_PROT; - -### Output the dumping function tables - -push @trace_lines, "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n"; -foreach $req (@requests) -{ - push @trace_lines, " (dump_func)dump_${req}_request,\n"; -} -push @trace_lines, "};\n\n"; - -push @trace_lines, "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n"; -foreach $req (@requests) -{ - push @trace_lines, " (dump_func)", $replies{$req} ? "dump_${req}_reply,\n" : "0,\n"; -} -push @trace_lines, "};\n\n"; - -push @trace_lines, "static const char * const req_names[REQ_NB_REQUESTS] = {\n"; -foreach $req (@requests) -{ - push @trace_lines, " \"$req\",\n"; -} -push @trace_lines, "};\n"; - -REPLACE_IN_FILE( "server/trace.c", @trace_lines ); - -### Output the request handlers list - -my @request_lines = (); - -foreach $req (@requests) { push @request_lines, "DECL_HANDLER($req);\n"; } -push @request_lines, "\n#ifdef WANT_REQUEST_HANDLERS\n\n"; -push @request_lines, "typedef void (*req_handler)( const void *req, void *reply );\n"; -push @request_lines, "static const req_handler req_handlers[REQ_NB_REQUESTS] =\n{\n"; -foreach $req (@requests) -{ - push @request_lines, " (req_handler)req_$req,\n"; -} -push @request_lines, "};\n#endif /* WANT_REQUEST_HANDLERS */\n"; - -REPLACE_IN_FILE( "server/request.h", @request_lines ); ### Parse the request definitions -sub PARSE_REQUESTS +sub PARSE_REQUESTS() { # states: 0 = header 1 = declarations 2 = inside @REQ 3 = inside @REPLY my $state = 0; @@ -246,7 +169,7 @@ sub PARSE_REQUESTS ### Generate a dumping function -sub DO_DUMP_FUNC +sub DO_DUMP_FUNC($$@) { my $name = shift; my $req = shift; @@ -288,7 +211,7 @@ sub DO_DUMP_FUNC ### Retrieve the server protocol version from the existing server_protocol.h file -sub GET_PROTOCOL_VERSION +sub GET_PROTOCOL_VERSION() { my $protocol = 0; open SERVER_PROT, "include/wine/server_protocol.h" or return 0; @@ -302,7 +225,7 @@ sub GET_PROTOCOL_VERSION ### Replace the contents of a file between ### make_requests ### marks -sub REPLACE_IN_FILE +sub REPLACE_IN_FILE($@) { my $name = shift; my @data = @_; @@ -323,3 +246,69 @@ sub REPLACE_IN_FILE print FILE @lines; close(FILE); } + +### Main + +# Get the server protocol version +my $protocol = GET_PROTOCOL_VERSION(); + +### Create server_protocol.h and print header + +open SERVER_PROT, ">include/wine/server_protocol.h" or die "Cannot create include/wine/server_protocol.h"; +print SERVER_PROT "/*\n * Wine server protocol definitions\n *\n"; +print SERVER_PROT " * This file is automatically generated; DO NO EDIT!\n"; +print SERVER_PROT " * Edit server/protocol.def instead and re-run tools/make_requests\n"; +print SERVER_PROT " */\n\n"; +print SERVER_PROT "#ifndef __WINE_WINE_SERVER_PROTOCOL_H\n"; +print SERVER_PROT "#define __WINE_WINE_SERVER_PROTOCOL_H\n"; + +### Parse requests to find request/reply structure definitions + +PARSE_REQUESTS(); + +### Build the request list and structures + +print SERVER_PROT "\n\nenum request\n{\n"; +foreach my $req (@requests) { print SERVER_PROT " REQ_$req,\n"; } +print SERVER_PROT " REQ_NB_REQUESTS\n};\n\n"; + +print SERVER_PROT "union generic_request\n{\n"; +print SERVER_PROT " struct request_max_size max_size;\n"; +print SERVER_PROT " struct request_header request_header;\n"; +foreach my $req (@requests) { print SERVER_PROT " struct ${req}_request ${req}_request;\n"; } +print SERVER_PROT "};\n"; + +print SERVER_PROT "union generic_reply\n{\n"; +print SERVER_PROT " struct request_max_size max_size;\n"; +print SERVER_PROT " struct reply_header reply_header;\n"; +foreach my $req (@requests) { print SERVER_PROT " struct ${req}_reply ${req}_reply;\n"; } +print SERVER_PROT "};\n\n"; + +printf SERVER_PROT "#define SERVER_PROTOCOL_VERSION %d\n\n", $protocol + 1; +print SERVER_PROT "#endif /* __WINE_WINE_SERVER_PROTOCOL_H */\n"; +close SERVER_PROT; + +### Output the dumping function tables + +push @trace_lines, "static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n"; +foreach my $req (@requests) +{ + push @trace_lines, " (dump_func)dump_${req}_request,\n"; +} +push @trace_lines, "};\n\n"; + +push @trace_lines, "static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n"; +foreach my $req (@requests) +{ + push @trace_lines, " (dump_func)", $replies{$req} ? "dump_${req}_reply,\n" : "0,\n"; +} +push @trace_lines, "};\n\n"; + +push @trace_lines, "static const char * const req_names[REQ_NB_REQUESTS] = {\n"; +foreach my $req (@requests) +{ + push @trace_lines, " \"$req\",\n"; +} +push @trace_lines, "};\n"; + +REPLACE_IN_FILE( "server/trace.c", @trace_lines );