| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# Perl script to insert the name of a release directory into the aceversion.c |
| 4 |
# source file. |
| 5 |
# |
| 6 |
# We need this to happen so that we can be sure which version of the source |
| 7 |
# code users are compiling from. Currently it isn't obvious to us except |
| 8 |
# by update level which does not change for monthly updates. |
| 9 |
# |
| 10 |
# Script will fail if aceversion.c is not writeable. |
| 11 |
# |
| 12 |
# |
| 13 |
|
| 14 |
# Initialise... |
| 15 |
$debug = 0 ; # Debug flag, may be reset from command line... |
| 16 |
|
| 17 |
($cmd = $0) =~ s#.*/## ; # Get this commands basename (got this |
| 18 |
# magic from 'Learning Perl', p. 214.). |
| 19 |
|
| 20 |
$msghdr = $cmd . ': ' ; # Set up a prefix for error messages. |
| 21 |
|
| 22 |
$source_file = 'aceversion.c' ; # The ACEDB source file to be searched. |
| 23 |
|
| 24 |
|
| 25 |
# We don't want any arguments to the script. |
| 26 |
# |
| 27 |
($debug) && print $msghdr . "program arguments - @ARGV\n" ; |
| 28 |
($#ARGV != 1) && die $msghdr . "Wrong number of parameters supplied, specify: <aceversion.c_source_directory> <RELEASE.YYYY_MM_DD>\n" ; |
| 29 |
|
| 30 |
|
| 31 |
# This is the location of the aceversion.c file we want to read. |
| 32 |
# |
| 33 |
$input_file = "@ARGV[0]/$source_file" ; |
| 34 |
$output_file = "$input_file.tmp" ; |
| 35 |
|
| 36 |
$release_dir = @ARGV[1] ; |
| 37 |
|
| 38 |
# Now check out the input file to see if it's OK... |
| 39 |
(-f $input_file && -r $input_file && -w $input_file) || die $msghdr . "file specified is not a file, or is not readable/writeable by this program.\n" ; |
| 40 |
|
| 41 |
# Open the input file... |
| 42 |
open(INFILE, $input_file) || die $msghdr . "could not open $input_file\n" ; |
| 43 |
|
| 44 |
open(OUTFILE, ">$output_file") || die $msghdr . "could not open $output_file\n" ; |
| 45 |
|
| 46 |
# Now start parsing the input file... |
| 47 |
while (<INFILE>) |
| 48 |
{ |
| 49 |
($debug) && print $msghdr . "Data just read in $_\n" ; |
| 50 |
|
| 51 |
# Once we find the start tag we know that the version, release & update are on the next |
| 52 |
# three lines. |
| 53 |
if ( /ACE_RELEASE_DIR_START/ ) |
| 54 |
{ |
| 55 |
print OUTFILE "$_" ; |
| 56 |
|
| 57 |
$release_dir_line = <INFILE> ; |
| 58 |
($define, $label, $junk) = split(/\s+/, $release_dir_line) ; |
| 59 |
print OUTFILE "$define $label \"$release_dir\"\n" ; |
| 60 |
} |
| 61 |
else |
| 62 |
{ |
| 63 |
print OUTFILE "$_" ; |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
# Don't need the file anymore so close it... |
| 69 |
close(INFILE) || die $msghdr . "could not close $input_file\n" ; |
| 70 |
|
| 71 |
close(OUTFILE) || die $msghdr . "could not close $output_file\n" ; |
| 72 |
|
| 73 |
|
| 74 |
# overwrite the old version of the file with the new one. |
| 75 |
rename ($output_file, $input_file) || die $msghdr . "rename of $output_file to $input_file failed.\n" ; |
| 76 |
|
| 77 |
($debug) && print $msghdr . "File successfully processed...\n" ; |
| 78 |
|
| 79 |
exit 0 ; |
| 80 |
|