OSSP CVS Repository

ossp - ossp-pkg/shtool/sh.version 1.21
Not logged in
[Honeypot]  [Browse]  [Directory]  [Home]  [Login
[Reports]  [Search]  [Ticket]  [Timeline
  [Raw

ossp-pkg/shtool/sh.version 1.21
##
##  version -- Generate and maintain a version information file
##  Copyright (c) 1994-2000 Ralf S. Engelschall <rse@engelschall.com>
##  Originally written for ePerl
##
##  This file is part of shtool and free software; you can redistribute
##  it and/or modify it under the terms of the GNU General Public
##  License as published by the Free Software Foundation; either version
##  2 of the License, or (at your option) any later version.
##
##  This file is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
##  General Public License for more details.
##
##  You should have received a copy of the GNU General Public License
##  along with this program; if not, write to the Free Software
##  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
##  USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
##

str_tool="version"
str_usage="[-l<lang>] [-n<name>] [-p<prefix>] [-s<version>] [-i<knob>] [-d<type>] <file>"
arg_spec="1+"
opt_spec="l:n:p:s:i:d:"
opt_l="txt"
opt_n="unknown"
opt_p="unknown"
opt_s="unknown"
opt_i="P"
opt_d="NO"
gen_tmpfile=yes

. ./sh.common

LANGUAGE="$opt_l"
NAME="$opt_n"
PREFIX="$opt_p"
FULLVERSION="$opt_s"
INCREASE="$opt_i"
REPORT="$opt_d"
FILE="$1"

#   determine language
if [ ".$LANGUAGE" = .unknown ]; then
    case $FILE in
        *.txt )       LANGUAGE=txt    ;;
        *.c )         LANGUAGE=c      ;;
        *.pl | *.pm ) LANGUAGE=perl   ;;
        *.py)         LANGUAGE=python ;;
        * )           echo "$tool:Error: unknown language type" 1>&2; exit 1 ;;
    esac
fi

#   determine prefix from name and vice versa
if [ ".$PREFIX" = . -o ".$PREFIX" = .unknown ]; then
    if [ ".$NAME" != . -a ".$NAME" != .unknown ]; then
        PREFIX="$NAME"
    fi
fi
if [ ".$NAME" = . -o ".$NAME" = .unknown ]; then
    if [ ".$PREFIX" != . -a ".$PREFIX" != .unknown ]; then
        NAME="$PREFIX"
    fi
fi

#   determine version
date=unknown
version=0
revision=0
bplevel=0
if [ ".$FULLVERSION" = .unknown ]; then
    if [ -r "$FILE" ]; then
        #   grep out current information
        id=`grep 'Version [0-9]*.[0-9]*[.abps][0-9]* ([0-9]*-[a-zA-Z]*-[0-9]*)' $FILE | \
            head -1 | \
            sed -e 's%.*Version \([0-9]*\)\.\([0-9]*\)\([.abps]\)\([0-9]*\) (\([0-9]*-[a-zA-Z]*-[0-9]*\)).*%\1:\2:\3:\4:\5%'`
        version=`echo $id | awk -F: '{ print $1 }'`
        revision=`echo $id | awk -F: '{ print $2 }'`
        bptype=`echo $id | awk -F: '{ print $3 }'`
        bplevel=`echo $id | awk -F: '{ print $4 }'`
        date=`echo $id | awk -F: '{ print $5 }'`
        if [ .$REPORT = .NO ]; then
            case $INCREASE in
                b ) bplevel=`expr $bplevel + 1`
                    bptype=b
                    ;;
                a ) bplevel=`expr $bplevel + 1`
                    bptype=a
                    ;;
                s ) bplevel=`expr $bplevel + 1`
                    bptype=s
                    ;;
                P ) bplevel=`expr $bplevel + 1`
                    bptype=.
                    ;;
                p ) bplevel=`expr $bplevel + 1`
                    bptype=p
                    ;;
                r ) revision=`expr $revision + 1`
                    bptype=.
                    bplevel=0
                    ;;
                v ) version=`expr $version + 1`
                    revision=0
                    bptype=.
                    bplevel=0
                    ;;
            esac
            date=calc
        fi
        FULLVERSION="$version.$revision$bptype$bplevel"
    else
        #   intialise to first version
        version=0
        revision=5
        bptype=b
        bplevel=0
        date=calc
    fi
else
    #   take given version
    V=`echo $FULLVERSION | sed -e 's%\([0-9]*\)\.\([0-9]*\)\([.abps]\)\([0-9]*\).*%\1:\2:\3:\4%'`
    version=`echo $V | awk -F: '{ print $1 }'`
    revision=`echo $V | awk -F: '{ print $2 }'`
    bptype=`echo $V | awk -F: '{ print $3 }'`
    bplevel=`echo $V | awk -F: '{ print $4 }'`
    date=calc
fi

#   determine hex value of version
case $FULLVERSION in
    *.*a* )
        HEX=`echo "$FULLVERSION" | sed -e 's/a.*//' | awk -F. '{ printf("%d%02d", $1, $2); }' &&
             echo "$FULLVERSION" | sed -e 's/.*a//' | awk '{ printf("0%02d", $1); }'`
        ;;
    *.*b* )
        HEX=`echo "$FULLVERSION" | sed -e 's/b.*//' | awk -F. '{ printf("%d%02d", $1, $2); }' &&
             echo "$FULLVERSION" | sed -e 's/.*b//' | awk '{ printf("1%02d", $1); }'`
        ;;
    *.*.* )
        HEX=`echo "$FULLVERSION" | awk -F. '{ printf("%d%02d2%02d", $1, $2, $3); }'`
        ;;
esac

#   determine libtool version
case $FULLVERSION in
    *.*a* )
        LTV=`echo "$FULLVERSION" | sed -e 's/a.*//' | awk -F. '{ printf("%d:0", $1*10+$2); }'`
        ;;
    *.*b* )
        LTV=`echo "$FULLVERSION" | sed -e 's/b.*//' | awk -F. '{ printf("%d:0", $1*10+$2); }'`
        ;;
    *.*.* )
        LTV=`echo "$FULLVERSION" | awk -F. '{ printf("%d:%d", $1*10+$2, $3); }'`
        ;;
esac

#   determine string out of filename
#   (don't try to optimize this in any way - portability!)
FILESTR=`echo "$FILE" |\
         tr 'abcdefghijklmnopqrstuvwxyz./%+' \
            'ABCDEFGHIJKLMNOPQRSTUVWXYZ____' | sed -e 's/-/_/g'`

#   determine date
if [ ".$date" = .calc ]; then
    day=`date '+%d'`
    month=`date '+%m'`
    year=`date '+%Y' 2>/dev/null`
    if [ ".$time_year" = . ]; then
        year=`date '+%y'`
        case $year in
            [5-9][0-9]) year="19$year" ;;
            [0-4][0-9]) year="20$year" ;;
        esac
    fi
    case $month in
        1|01) month='Jan' ;;
        2|02) month='Feb' ;;
        3|03) month='Mar' ;;
        4|04) month='Apr' ;;
        5|05) month='May' ;;
        6|06) month='Jun' ;;
        7|07) month='Jul' ;;
        8|08) month='Aug' ;;
        9|09) month='Sep' ;;
          10) month='Oct' ;;
          11) month='Nov' ;;
          12) month='Dec' ;;
    esac
    date="${day}-${month}-${year}"
fi

if [ .$REPORT != .NO ]; then
    case $REPORT in
        long )
            echo "$version.$revision$bptype$bplevel ($date)"
            ;;
        short )
            echo "$version.$revision$bptype$bplevel"
            ;;
        libtool )
            echo "$LTV"
            ;;
        hex )
            echo "0x$HEX"
            ;;
    esac
    rm -f $tmpfile >/dev/null 2>&1
    exit 0
fi

#   create the version file according the the selected language
echo "new version: $version.$revision$bptype$bplevel ($date)"
case $LANGUAGE in
    txt )
        cat >$tmpfile <<'EOT'

  This is @NAME@, Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)

EOT
        ;;
    c )
        cat >$tmpfile <<'EOT'
/*
**  @FILE@ -- Version Information
**  [automatically generated and maintained by GNU shtool]
*/

#ifdef _AS_HEADER

#ifndef _@FILESTR@
#define _@FILESTR@
#define @PREFIX@_VERSION 0x@HEX@
extern const int  @PREFIX@_Version;
extern const char @PREFIX@_VersionStr[];
extern const char @PREFIX@_Hello[];
extern const char @PREFIX@_GNUVersion[];
extern const char @PREFIX@_WhatID[];
extern const char @PREFIX@_RCSIdentID[];
extern const char @PREFIX@_WebID[];
extern const char @PREFIX@_PlainID[];
#endif /* _@FILESTR@ */

#else

const int  @PREFIX@_Version      = 0x@HEX@;
const char @PREFIX@_VersionStr[] = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
const char @PREFIX@_Hello[]      = "This is @NAME@, Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
const char @PREFIX@_GNUVersion[] = "@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
const char @PREFIX@_WhatID[]     = "@(#)@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
const char @PREFIX@_RCSIdentID[] = "$Id: @NAME@ @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ @DAY@-@MONTH@-@YEAR@ $";
const char @PREFIX@_WebID[]      = "@NAME@/@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
const char @PREFIX@_PlainID[]    = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";

#endif

EOT
        ;;
    perl )
        cat >$tmpfile <<'EOT'
##
##  @FILE@ -- Version Information
##  [automatically generated and maintained by GNU shtool]
##

$@PREFIX@_Version    = 0x@HEX@;
$@PREFIX@_VersionStr = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
$@PREFIX@_Hello      = "This is @NAME@, Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
$@PREFIX@_GNUVersion = "@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
$@PREFIX@_WhatID     = "@(#)@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
$@PREFIX@_RCSIdentID = "\$Id: @NAME@ @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ @DAY@-@MONTH@-@YEAR@ $/";
$@PREFIX@_WebID      = "@NAME@/@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
$@PREFIX@_PlainID    = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";

1;
EOT
        ;;
    python )
        cat >$tmpfile <<'EOT'
##
##  @FILE@ -- Version Information
##  [automatically generated and maintained by GNU shtool]
##

@PREFIX@_Version    = 0x@HEX@
@PREFIX@_VersionStr = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)"
@PREFIX@_Hello      = "This is @NAME@, Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)"
@PREFIX@_GNUVersion = "@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@"
@PREFIX@_WhatID     = "@(#)@NAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)"
@PREFIX@_RCSIdentID = "$Id: @NAME@ @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ @DAY@-@MONTH@-@YEAR@ $"
@PREFIX@_WebID      = "@NAME@/@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@"
@PREFIX@_PlainID    = "@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@"

EOT
        ;;
esac

#   now create the version file
rm -f $FILE >/dev/null 2>&1
sed \
    -e "s|@FILE@|$FILE|g" \
    -e "s|@FILESTR@|$FILESTR|g" \
    -e "s|@PREFIX@|$PREFIX|g" \
    -e "s|@NAME@|$NAME|g" \
    -e "s|@HEX@|$HEX|g" \
    -e "s|@VERSION@|$version|g" \
    -e "s|@REVISION@|$revision|g" \
    -e "s|@BPTYPE@|$bptype|g" \
    -e "s|@BPLEVEL@|$bplevel|g" \
    -e "s|@YEAR@|$year|g" \
    -e "s|@MONTH@|$month|g" \
    -e "s|@DAY@|$day|g" <$tmpfile >$FILE
rm -f $tmpfile >/dev/null 2>&1
exit 0


CVSTrac 2.0.1