Module: wine Branch: master Commit: 37f3691f7f10d89f1185f55c8ff04c8e46a92986 URL: http://source.winehq.org/git/wine.git/?a=commit;h=37f3691f7f10d89f1185f55c8f...
Author: Alexandre Julliard julliard@winehq.org Date: Wed Dec 10 17:13:30 2008 +0100
tools: Re-use the file updating routines from make_makefiles in make_requests.
---
tools/make_requests | 74 +++++++++++++++++++++++++++++++++++++------------- 1 files changed, 55 insertions(+), 19 deletions(-)
diff --git a/tools/make_requests b/tools/make_requests index 227ac27..2c06813 100755 --- a/tools/make_requests +++ b/tools/make_requests @@ -258,28 +258,57 @@ sub GET_ERROR_NAMES() return %errors; }
-### Replace the contents of a file between ### make_requests ### marks +# update a file if changed +sub update_file($) +{ + my $file = shift; + my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null"; + if (!$ret) + { + unlink "$file.new"; + } + else + { + rename "$file.new", "$file"; + print "$file updated\n"; + } + return $ret; +}
-sub REPLACE_IN_FILE($@) +# replace some lines in a file between two markers +sub replace_in_file($$$@) { - my $name = shift; - my @data = @_; - my @lines = (); - open(FILE,$name) or die "Can't open $name"; - while (<FILE>) + my $file = shift; + my $start = shift; + my $end = shift; + + open NEW_FILE, ">$file.new" or die "cannot create $file.new"; + + if (defined($start)) { - push @lines, $_; - last if /### make_requests begin ###/; + open OLD_FILE, "$file" or die "cannot open $file"; + while (<OLD_FILE>) + { + print NEW_FILE $_; + last if /$start/; + } } - push @lines, "\n", @data; - while (<FILE>) + + print NEW_FILE "\n", @_, "\n"; + + if (defined($end)) { - if (/### make_requests end ###/) { push @lines, "\n", $_; last; } + my $skip=1; + while (<OLD_FILE>) + { + $skip = 0 if /$end/; + print NEW_FILE $_ unless $skip; + } } - push @lines, <FILE>; - open(FILE,">$name") or die "Can't modify $name"; - print FILE @lines; - close(FILE); + + 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 );