1 | #!@PERL@ -w |
---|
2 | # |
---|
3 | # gtk-doc - GTK DocBook documentation generator. |
---|
4 | # Copyright (C) 2001 Damon Chaplin |
---|
5 | # |
---|
6 | # This program is free software; you can redistribute it and/or modify |
---|
7 | # it under the terms of the GNU General Public License as published by |
---|
8 | # the Free Software Foundation; either version 2 of the License, or |
---|
9 | # (at your option) any later version. |
---|
10 | # |
---|
11 | # This program is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with this program; if not, write to the Free Software |
---|
18 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
19 | # |
---|
20 | |
---|
21 | # |
---|
22 | # These are functions used by several of the gtk-doc Perl scripts. |
---|
23 | # I'll move more of the common routines here eventually, though I need to |
---|
24 | # stop them from using global variables. |
---|
25 | # |
---|
26 | |
---|
27 | 1; |
---|
28 | |
---|
29 | |
---|
30 | ############################################################################# |
---|
31 | # Function : UpdateFileIfChanged |
---|
32 | # Description : Compares the old version of the file with the new version and |
---|
33 | # if the file has changed it moves the new version into the old |
---|
34 | # versions place. This is used so we only change files if |
---|
35 | # needed, so we can do proper dependency tracking and we don't |
---|
36 | # needlessly check files into CVS that haven't changed. |
---|
37 | # It returns 0 if the file hasn't changed, and 1 if it has. |
---|
38 | # Arguments : $old_file - the pathname of the old file. |
---|
39 | # $new_file - the pathname of the new version of the file. |
---|
40 | # $make_backup - 1 if a backup of the old file should be kept. |
---|
41 | # It will have the .bak suffix added to the file name. |
---|
42 | ############################################################################# |
---|
43 | |
---|
44 | sub UpdateFileIfChanged { |
---|
45 | my ($old_file, $new_file, $make_backup) = @_; |
---|
46 | |
---|
47 | # print "Comparing $old_file with $new_file...\n"; |
---|
48 | |
---|
49 | # If the old file doesn't exist we want this to default to 1. |
---|
50 | my $exit_code = 1; |
---|
51 | |
---|
52 | if (-e $old_file) { |
---|
53 | `cmp -s $old_file $new_file`; |
---|
54 | $exit_code = $? >> 8; |
---|
55 | # print " cmp exit code: $exit_code ($?)\n"; |
---|
56 | } |
---|
57 | |
---|
58 | if ($exit_code > 1) { |
---|
59 | die "Error running 'cmp $old_file $new_file'"; |
---|
60 | } |
---|
61 | |
---|
62 | if ($exit_code == 1) { |
---|
63 | # print " files changed - replacing old version with new version.\n"; |
---|
64 | |
---|
65 | if ($make_backup && -e $old_file) { |
---|
66 | rename ($old_file, "$old_file.bak") |
---|
67 | || die "Can't move $old_file to $old_file.bak: $!"; |
---|
68 | } |
---|
69 | |
---|
70 | rename ($new_file, $old_file) |
---|
71 | || die "Can't move $new_file to $old_file: $!"; |
---|
72 | |
---|
73 | return 1; |
---|
74 | } else { |
---|
75 | # print " files the same - deleting new version.\n"; |
---|
76 | |
---|
77 | unlink ("$new_file") |
---|
78 | || die "Can't delete file: $new_file: $!"; |
---|
79 | |
---|
80 | return 0; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|