tools: Re-use the file updating routines from make_makefiles in make_requests.

This commit is contained in:
Alexandre Julliard 2008-12-10 17:13:30 +01:00
parent 517b2f624d
commit 37f3691f7f
1 changed files with 56 additions and 20 deletions

View File

@ -258,28 +258,57 @@ sub GET_ERROR_NAMES()
return %errors;
}
### Replace the contents of a file between ### make_requests ### marks
sub REPLACE_IN_FILE($@)
# update a file if changed
sub update_file($)
{
my $name = shift;
my @data = @_;
my @lines = ();
open(FILE,$name) or die "Can't open $name";
while (<FILE>)
my $file = shift;
my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
if (!$ret)
{
push @lines, $_;
last if /\#\#\# make_requests begin \#\#\#/;
unlink "$file.new";
}
push @lines, "\n", @data;
while (<FILE>)
else
{
if (/\#\#\# make_requests end \#\#\#/) { push @lines, "\n", $_; last; }
rename "$file.new", "$file";
print "$file updated\n";
}
push @lines, <FILE>;
open(FILE,">$name") or die "Can't modify $name";
print FILE @lines;
close(FILE);
return $ret;
}
# replace some lines in a file between two markers
sub replace_in_file($$$@)
{
my $file = shift;
my $start = shift;
my $end = shift;
open NEW_FILE, ">$file.new" or die "cannot create $file.new";
if (defined($start))
{
open OLD_FILE, "$file" or die "cannot open $file";
while (<OLD_FILE>)
{
print NEW_FILE $_;
last if /$start/;
}
}
print NEW_FILE "\n", @_, "\n";
if (defined($end))
{
my $skip=1;
while (<OLD_FILE>)
{
$skip = 0 if /$end/;
print NEW_FILE $_ unless $skip;
}
}
close OLD_FILE if defined($start);
close NEW_FILE;
return update_file($file);
}
### Main
@ -291,7 +320,7 @@ my %errors = GET_ERROR_NAMES();
### Create server_protocol.h and print header
open SERVER_PROT, ">include/wine/server_protocol.h" or die "Cannot create include/wine/server_protocol.h";
open SERVER_PROT, ">include/wine/server_protocol.h.new" or die "Cannot create include/wine/server_protocol.h.new";
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";
@ -324,6 +353,7 @@ 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;
update_file( "include/wine/server_protocol.h" );
### Output the dumping function tables
@ -360,7 +390,10 @@ foreach my $err (sort keys %errors)
push @trace_lines, " { NULL, 0 }\n";
push @trace_lines, "};\n";
REPLACE_IN_FILE( "server/trace.c", @trace_lines );
replace_in_file( "server/trace.c",
"### make_requests begin ###",
"### make_requests end ###",
@trace_lines );
### Output the request handlers list
@ -376,4 +409,7 @@ foreach my $req (@requests)
}
push @request_lines, "};\n#endif /* WANT_REQUEST_HANDLERS */\n";
REPLACE_IN_FILE( "server/request.h", @request_lines );
replace_in_file( "server/request.h",
"### make_requests begin ###",
"### make_requests end ###",
@request_lines );