Debian Codegraph @

wtools/aceGetVersion

raw
1 #!/usr/local/bin/perl
2 #
3 # Perl script to read the acedb kernel version from the source file that
4 # holds the version number: aceversion.c
5 #
6 # The idea is that only the version.c source file will be altered when changing
7 # the ACEDB version number, then the scripts that produce the public tar files
8 # will use this script to get that version number.
9 #
10 # The script returns the version, release and update read from aceversion.c
11 # in the form: <version>.<release>.<update> e.g. 4.9.27
12 #
13 # it must be given the name of the directory where aceversion.c can be found.
14 #
15
16 # Initialise...
17 $debug = 0 ; # Debug flag, may be reset from command line...
18
19 ($cmd = $0) =~ s#.*/## ; # Get this commands basename (got this
20 # magic from 'Learning Perl', p. 214.).
21
22 $msghdr = $cmd . ': ' ; # Set up a prefix for error messages.
23
24 $source_file = 'aceversion.c' ; # The ACEDB source file to be searched.
25
26
27 # Parse command line options:
28 # -d turns on debugging
29 #
30 require "getopts.pl" ;
31 &Getopts('d') ;
32 if ($opt_d == 1) { $debug = $opt_d ;}
33
34
35 # We don't want any arguments to the script.
36 #
37 ($debug) && print $msghdr . "program arguments - @ARGV\n" ;
38 ($#ARGV < 0 || $#ARGV > 0) && die $msghdr . "Wrong number of parameters supplied, specify JUST the directory where aceversion.c can be found.\n" ;
39
40
41 # This is the location of the aceversion.c file we want to read.
42 #
43 $input_file = "@ARGV[0]/$source_file" ;
44
45 # Now check out the input file to see if it's OK...
46 (-f $input_file && -r $input_file) || die $msghdr . "file specified is not a file, or is not readable by this program.\n" ;
47
48 # Open the input file...
49 open(INFILE, $input_file) || die $msghdr . "could not open source code file\n" ;
50
51 # Now start parsing the input file...
52 while (<INFILE>)
53 {
54 ($debug) && print $msghdr . "Data just read in $&\n" ;
55
56 # Once we find the start tag we know that the version, release & update are on the next
57 # three lines.
58 if ( /ACE_VERSION_START/ )
59 {
60 $version_line = <INFILE> ;
61 ($junk, $junk, $version, $junk) = split(/\s+/, $version_line) ;
62 $release_line = <INFILE> ;
63 ($junk, $junk, $release, $junk) = split(/\s+/, $release_line) ;
64 $update_line = <INFILE> ;
65 ($junk, $junk, $update , $junk) = split(/\s+/, $update_line) ;
66 }
67
68 }
69
70 # Don't need the file anymore so close it...
71 close(INFILE) || die $msghdr . "could not close source file\n" ;
72
73 ($debug) && print $msghdr . "File successfully processed...\n" ;
74
75 # Return the result as a single string sent to STDOUT in the form "4.9.27"
76 print "$version\.$release\.$update\n" ;
77
78 exit 0 ;
79