Commit 37ec9275 authored by Alexandre Julliard's avatar Alexandre Julliard

Use the new protocol.def file to build the request structures.

Define protocol structures in a separate server_protocol.h file. Removed __WINE_SERVER__ checks now that all includes are in the right directory.
parent 02014661
DEFS = -D__WINE__ -D__WINE_SERVER__
DEFS = -D__WINE__
TOPSRCDIR = @top_srcdir@
TOPOBJDIR = ..
SRCDIR = @srcdir@
......
......@@ -7,13 +7,9 @@
#ifndef __WINE_SERVER_HANDLE_H
#define __WINE_SERVER_HANDLE_H
#ifndef __WINE_SERVER__
#error This file can only be used in the Wine server
#endif
#include <stdlib.h>
#include "windef.h"
#include "server.h"
#include "wine/server_protocol.h"
struct process;
struct object_ops;
......
......@@ -7,13 +7,9 @@
#ifndef __WINE_SERVER_OBJECT_H
#define __WINE_SERVER_OBJECT_H
#ifndef __WINE_SERVER__
#error This file can only be used in the Wine server
#endif
#include <sys/poll.h>
#include <sys/time.h>
#include "server.h"
#include "wine/server_protocol.h"
#define DEBUG_OBJECTS
......
......@@ -7,10 +7,6 @@
#ifndef __WINE_SERVER_PROCESS_H
#define __WINE_SERVER_PROCESS_H
#ifndef __WINE_SERVER__
#error This file can only be used in the Wine server
#endif
#include "object.h"
struct msg_queue;
......
......@@ -30,7 +30,6 @@
#include "wincon.h"
#include "thread.h"
#include "process.h"
#include "server.h"
#define WANT_REQUEST_HANDLERS
#include "request.h"
#include "wine/port.h"
......
......@@ -7,11 +7,8 @@
#ifndef __WINE_SERVER_REQUEST_H
#define __WINE_SERVER_REQUEST_H
#ifndef __WINE_SERVER__
#error This file can only be used in the Wine server
#endif
#include "thread.h"
#include "wine/server_protocol.h"
/* max request length */
#define MAX_REQUEST_LENGTH 8192
......
......@@ -7,10 +7,6 @@
#ifndef __WINE_SERVER_THREAD_H
#define __WINE_SERVER_THREAD_H
#ifndef __WINE_SERVER__
#error This file can only be used in the Wine server
#endif
#include "object.h"
/* thread structure */
......
......@@ -7,10 +7,6 @@
#ifndef __WINE_SERVER_UNICODE_H
#define __WINE_SERVER_UNICODE_H
#ifndef __WINE_SERVER__
#error This file can only be used in the Wine server
#endif
#include "windef.h"
#include "wine/unicode.h"
#include "object.h"
......
#! /usr/bin/perl -w
#
# Build the server/trace.c and server/request.h files
# from the contents of include/server.h.
# from the contents of include/wine/server.h.
#
# Copyright (C) 1998 Alexandre Julliard
#
......@@ -21,18 +21,38 @@
my @requests = ();
my %replies = ();
open(SERVER,"include/server.h") or die "Can't open include/server.h";
my @trace_lines = ();
### Parse server.h to find request/reply structure definitions
# Get the server protocol version
my $protocol = &GET_PROTOCOL_VERSION;
my @trace_lines = ();
my $protocol = 0; # server protocol version
### Create server_protocol.h and print header
while (<SERVER>)
{
if (/^struct +(\w+)_request/) { &DO_REQUEST($1); }
if (/^\#define SERVER_PROTOCOL_VERSION (\d+)/) { $protocol = $1 + 1; }
}
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
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 header;\n";
foreach $req (@requests) { print SERVER_PROT " struct ${req}_request $req;\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
......@@ -59,22 +79,6 @@ push @trace_lines, "};\n";
REPLACE_IN_FILE( "server/trace.c", @trace_lines );
### Replace the request list in server.h by the new values
my @server_lines = ();
push @server_lines, "enum request\n{\n";
foreach $req (@requests) { push @server_lines, " REQ_$req,\n"; }
push @server_lines, " REQ_NB_REQUESTS\n};\n\n";
push @server_lines, "union generic_request\n{\n";
push @server_lines, " struct request_max_size max_size;\n";
push @server_lines, " struct request_header header;\n";
foreach $req (@requests) { push @server_lines, " struct ${req}_request $req;\n"; }
push @server_lines, "};\n\n";
push @server_lines, "#define SERVER_PROTOCOL_VERSION $protocol\n";
REPLACE_IN_FILE( "include/server.h", @server_lines );
### Output the request handlers list
my @request_lines = ();
......@@ -91,56 +95,106 @@ push @request_lines, "};\n#endif /* WANT_REQUEST_HANDLERS */\n";
REPLACE_IN_FILE( "server/request.h", @request_lines );
### Handle a request structure definition
### Parse the request definitions
sub DO_REQUEST
sub PARSE_REQUESTS
{
my $name = shift;
# states: 0 = header 1 = declarations 2 = inside @REQ 3 = inside @REPLY
my $state = 0;
my $name = "";
my @in_struct = ();
my @out_struct = ();
my $got_header = 0;
while (<SERVER>)
open(PROTOCOL,"server/protocol.def") or die "Can't open server/protocol.def";
while (<PROTOCOL>)
{
my ($dir, $type, $var);
last if /^};$/;
next if /^{$/;
my ($type, $var);
# strip comments
s!/\*.*\*/!!g;
next if /^\s*$/;
if (/REQUEST_HEADER/)
# strip white space at end of line
s/\s+$//;
if (/^\@HEADER/)
{
die "Misplaced \@HEADER" unless $state == 0;
$state++;
next;
}
# ignore everything while in state 0
next if $state == 0;
if (/^\@REQ\(\s*(\w+)\s*\)/)
{
die "Duplicated header" if $got_header;
die "Header must be first" if ($#in_struct != -1 || $#out_struct != -1);
$got_header++;
$name = $1;
die "Misplaced \@REQ" unless $state == 1;
# start a new request
@in_struct = ();
@out_struct = ();
print SERVER_PROT "struct ${name}_request\n{\n";
print SERVER_PROT " struct request_header __header;\n";
$state++;
next;
}
if (/^\s*(IN|OUT)\s*VARARG\((\w+),(\w+)\)/)
if (/^\@REPLY/)
{
$dir = $1;
$var = $2;
$type = "&dump_varargs_" . $3;
die "Misplaced \@REPLY" unless $state == 2;
$state++;
next;
}
elsif (/^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/)
if (/^\@END/)
{
$dir = $1;
$type = $2 . ($5 || "");
$var = $4;
die "Unrecognized type $type" unless (defined($formats{$type}) || $5);
die "Misplaced \@END" unless ($state == 2 || $state == 3);
print SERVER_PROT "};\n";
# got a complete request
push @requests, $name;
&DO_DUMP_FUNC( $name, "request", @in_struct);
if ($#out_struct >= 0)
{
$replies{$name} = 1;
&DO_DUMP_FUNC( $name, "reply", @out_struct);
}
$state = 1;
next;
}
else
if ($state != 1)
{
die "Unrecognized syntax $_";
# skip empty lines (but keep them in output file)
if (/^$/)
{
print SERVER_PROT "\n";
next;
}
if (/^\s*VARARG\((\w+),(\w+)\)/)
{
$var = $1;
$type = "&dump_varargs_" . $2;
s!(VARARG\(.*\)\s*;)!/* $1 */!;
}
elsif (/^\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/)
{
$type = $1 . ($4 || "");
$var = $3;
die "Unrecognized type $type" unless (defined($formats{$type}) || $4);
}
else
{
die "Unrecognized syntax $_";
}
if ($state == 2) { push @in_struct, $type, $var; }
if ($state == 3) { push @out_struct, $type, $var; }
}
if ($dir =~ /IN/) { push @in_struct, $type, $var; }
if ($dir =~ /OUT/) { push @out_struct, $type, $var; }
}
die "Missing header" unless $got_header;
push @requests, $name;
&DO_DUMP_FUNC( $name, "request", @in_struct);
if ($#out_struct >= 0)
{
$replies{$name} = 1;
&DO_DUMP_FUNC( $name, "reply", @out_struct);
# Pass it through into the output file
print SERVER_PROT $_ . "\n";
}
close PROTOCOL;
}
### Generate a dumping function
......@@ -191,6 +245,20 @@ sub DO_DUMP_FUNC
push @trace_lines, "}\n\n";
}
### Retrieve the server protocol version from the existing server_protocol.h file
sub GET_PROTOCOL_VERSION
{
my $protocol = 0;
open SERVER_PROT, "include/wine/server_protocol.h" or return 0;
while (<SERVER_PROT>)
{
if (/^\#define SERVER_PROTOCOL_VERSION (\d+)/) { $protocol = $1; last; }
}
close SERVER_PROT;
return $protocol;
}
### Replace the contents of a file between ### make_requests ### marks
sub REPLACE_IN_FILE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment