Subversion Repositories DevTools

Rev

Rev 255 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
#! perl
2
########################################################################
3
# Copyright ( C ) 2004 ERG Limited, All rights reserved
4
#
5
# Module name   : jats.sh
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
10
# Description   : Provide varions utility functions to process version
11
#                 package infrormation.
12
#
13
#......................................................................#
14
 
255 dpurdie 15
require 5.006_001;
227 dpurdie 16
use strict;
17
use warnings;
18
 
19
package JatsVersionUtils;
20
 
21
our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);
22
use Exporter;
23
 
24
$VERSION = 1.00;
25
@ISA = qw(Exporter);
26
 
27
# Symbols to autoexport (:DEFAULT tag)
28
@EXPORT = qw( SplitPackage
29
              SplitVersion
30
            );
31
 
32
#-------------------------------------------------------------------------------
33
# Function        : SplitVersion
34
#
35
# Description     : Extract the various fields from the version number
36
#
37
# Inputs          : $version        - Version data - without project extension
38
#
39
# Returns         : A list of:
40
#                       Major, Minor, Patch, Build, RawPatch
41
#
42
sub SplitVersion
43
{
44
    my ($version) = @_;
45
    my ($major, $minor, $patch ) = split ('\.', $version);
46
 
47
    #
48
    #   Decode the patch number and extract the build number
49
    #   Need to know the the length of the user string to decode
50
    #   Those less than three digits are build 0
51
    #
52
    my $build = 0;
53
    $minor = 0 unless ( $minor );
54
    $patch = 0 unless ( $patch );
55
    my $raw_patch = $patch;
56
    if ( length( $patch) >= 4 )
57
    {
58
        $build = substr( $patch, -3 ,3);
59
        $patch = substr( $patch,  0 ,length($patch)-3);
60
    }
61
 
62
    return ( $major, $minor, $patch, $build, $raw_patch );
63
}
64
 
65
#-------------------------------------------------------------------------------
66
# Function        : SplitPackage
67
#
68
# Description     : Split a package name and version into 4 parts
69
#
70
#                   Handle version of the form:
71
#                       1) text.suffix
72
#                       2) text<space>suffix
73
#                       3) text [No suffix]
74
#                   Assumptions:
75
#                       The project suffix is not numeric
76
#                       Versions of the form (nnnnnn).prj are a WIP
77
#                       
78
#
79
# Inputs          : $1  - Package name
80
#                   $2  - Package Version Input string
81
#
82
# Returns         : $0  - Package name
83
#                   $1  - Version part
84
#                   $2  - Suffix (project) part
85
#                   $4  - Reformed Version string
86
#
87
sub SplitPackage
88
{
89
    my ($package, $version) = @_;
90
 
91
    my $rel;
92
    my $suf;
93
    my $full;
94
 
95
    #
96
    #   Clean string(s)
97
    #
98
    $version =~ s~^\s+~~;
99
    $version =~ s~\s+$~~;
100
 
101
    $package =~ s~^\s+~~;
102
    $package =~ s~\s+$~~;
103
 
255 dpurdie 104
    if ( $version =~ m~^\((.*?)\)([\.]([^.0-9]+))$~ )
227 dpurdie 105
    {
106
        $rel = 'WIP';
107
        $suf = $3;
108
        $suf = '' unless ( $suf );
109
 
110
    }
255 dpurdie 111
    elsif ( $version =~ m~^(.*?)([\.\s]([^.0-9]+))$~ )
227 dpurdie 112
    {
113
        $rel = $1;
114
        $suf = $3;
115
        $suf = '' unless ( $suf );
116
    }
117
    else
118
    {
119
        $rel = $version;
120
        $suf = '';
121
    }
122
 
123
    #
124
    #   Generate a full version string
125
    #       xx.xx.xxxx.prj
126
    #
127
    $full = $rel;
128
    $full .= '.' . $suf if ( $suf );
129
 
130
    return ( $package, $rel, $suf, $full );
131
}
132
 
133
 
134
1;