OSSP CVS Repository

ossp - Difference in ossp-pkg/shtool/sh.version versions 1.21 and 1.22
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/shtool/sh.version 1.21 -> 1.22

--- sh.version   2000/06/14 19:01:26     1.21
+++ sh.version   2000/06/30 16:27:41     1.22
@@ -1,5 +1,5 @@
 ##
-##  version -- Generate and maintain a version information file
+##  version -- Maintain a version information file
 ##  Copyright (c) 1994-2000 Ralf S. Engelschall <rse@engelschall.com>
 ##  Originally written for ePerl
 ##
@@ -20,150 +20,118 @@
 ##
 
 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:"
+str_usage="[-l<lang>] [-n<name>] [-p<prefix>] [-s<version>] [-e] [-i<knob>] [-d<type>] <file>"
+arg_spec="1="
+opt_spec="l:n:p:s:i:e.d:"
 opt_l="txt"
-opt_n="unknown"
-opt_p="unknown"
-opt_s="unknown"
-opt_i="P"
-opt_d="NO"
-gen_tmpfile=yes
+opt_n=""
+opt_p=""
+opt_s=""
+opt_e="no"
+opt_i=""
+opt_d="short"
 
 . ./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
+file="$1"
 
 #   determine prefix from name and vice versa
-if [ ".$PREFIX" = . -o ".$PREFIX" = .unknown ]; then
-    if [ ".$NAME" != . -a ".$NAME" != .unknown ]; then
-        PREFIX="$NAME"
-    fi
+name="$opt_n"
+prefix="$opt_p"
+if [ ".$prefix" = . -a ".$name" != . ]; then
+    prefix="$name"
 fi
-if [ ".$NAME" = . -o ".$NAME" = .unknown ]; then
-    if [ ".$PREFIX" != . -a ".$PREFIX" != .unknown ]; then
-        NAME="$PREFIX"
-    fi
+if [ ".$name" = . -a ".$prefix" != . ]; then
+    name="$prefix"
 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
+#   determine current version
+triple="$opt_s"
+if [ ".$triple" != . ]; then
+    #   use given triple
+    if [ ".`echo $triple | grep '[0-9]*.[0-9]*[sabp.][0-9]*'`" = . ]; then
+        echo "$msgprefix:Error: invalid argument to option \`-s': \`$opt_s'" 1>&2
+        exit 1
     fi
+    V=`echo $triple |\
+       sed -e 's;\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\).*;\1:\2:\3:\4;'`
+    ver=`echo $V | awk -F: '{ print $1 }'`
+    rev=`echo $V | awk -F: '{ print $2 }'`
+    typ=`echo $V | awk -F: '{ print $3 }'`
+    lev=`echo $V | awk -F: '{ print $4 }'`
+    tim=calc
+elif [ -r $file ]; then
+    #   determine triple from given file
+    V=`grep 'Version [0-9]*.[0-9]*[sabp.][0-9]* ([0-9]*-[a-zA-Z]*-[0-9]*)' $file |\
+       head -1 | sed -e 's;.*Version \([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\) (\([0-9]*-[a-zA-Z]*-[0-9]*\)).*;\1:\2:\3:\4:\5;'`
+    ver=`echo $V | awk -F: '{ print $1 }'`
+    rev=`echo $V | awk -F: '{ print $2 }'`
+    typ=`echo $V | awk -F: '{ print $3 }'`
+    lev=`echo $V | awk -F: '{ print $4 }'`
+    tim=`echo $V | awk -F: '{ print $5 }'`
 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
+    #   intialise to first version
+    ver=0
+    rev=1
+    typ=.
+    lev=0
+    tim=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 new version in batch
+if [ ".$opt_i" != . ]; then
+    case $opt_i in
+        v ) ver=`expr $ver + 1`
+            rev=0
+            lev=0
+            ;;
+        r ) rev=`expr $rev + 1`
+            lev=0
+            ;;
+        l ) lev=`expr $lev + 1`
+            ;;
+        * ) echo "$msgprefix:Error: invalid argument to option \`-i': \`$opt_i'" 1>&2
+            exit 1
+            ;;
+    esac
+    tim=calc
+fi
 
-#   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 new version interactively
+if [ ".$opt_e" = .yes ]; then
+    echo "old version: ${ver}.${rev}${typ}${lev}"
+    while [ 1 ]; do
+        echo dummy | awk '{ printf("new version: "); }'
+        read triple
+        if [ ".`echo $triple | grep '[0-9]*.[0-9]*[sabp.][0-9]*'`" = . ]; then
+            echo "$msgprefix:Error: invalid version entered: \`$triple'" 1>&2
+            continue
+        fi
+        break
+    done
+    V=`echo $triple |\
+       sed -e 's;\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\).*;\1:\2:\3:\4;'`
+    ver=`echo $V | awk -F: '{ print $1 }'`
+    rev=`echo $V | awk -F: '{ print $2 }'`
+    typ=`echo $V | awk -F: '{ print $3 }'`
+    lev=`echo $V | awk -F: '{ print $4 }'`
+    tim=calc
+fi
 
-#   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 hexadecimal and libtool value of version
+case $typ in
+    a     ) typnum=0; levnum=$lev ;;
+    b     ) typnum=1; levnum=$lev ;;
+    p | . ) typnum=2; levnum=$lev ;;
+    s     ) typnum=9; levnum=99   ;; # snapshots are special
+esac
+hex=`echo "$ver:$rev:$typnum:$levnum" |\
+     awk -F: '{ printf("0x%d%02d%1d%02d", $1, $2, $3, $4); }'`
+ltv=`echo "$ver:$rev:$typnum:$levnum" |\
+     awk -F: '{ printf("%d:%d", $1*10 + $2, $3*10 + $2); }'`
 
 #   determine date
-if [ ".$date" = .calc ]; then
+if [ ".$tim" = .calc ]; then
     day=`date '+%d'`
     month=`date '+%m'`
     year=`date '+%Y' 2>/dev/null`
@@ -188,129 +156,141 @@
           11) month='Nov' ;;
           12) month='Dec' ;;
     esac
-    date="${day}-${month}-${year}"
+    tim="${day}-${month}-${year}"
 fi
 
-if [ .$REPORT != .NO ]; then
-    case $REPORT in
+#   perform result actions
+mode=show
+if [ ".$opt_i" != . ]; then
+    mode=edit
+elif [ ".$opt_e" = .yes ]; then
+    mode=edit
+elif [ ".$opt_s" != . ]; then
+    mode=edit
+fi
+if [ ".$mode" = .show ]; then
+    #   just display the current version
+    case $opt_d in
         long )
-            echo "$version.$revision$bptype$bplevel ($date)"
+            echo "${ver}.${rev}${typ}${lev} ($tim)"
             ;;
         short )
-            echo "$version.$revision$bptype$bplevel"
+            echo "${ver}.${rev}${typ}${lev}"
             ;;
         libtool )
-            echo "$LTV"
+            echo "${ltv}"
             ;;
         hex )
-            echo "0x$HEX"
+            echo "${hex}"
+            ;;
+        * ) echo "$msgprefix:Error: invalid argument to option \`-d': \`$opt_d'" 1>&2
+            exit 1
             ;;
     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@"
+else 
+    #   update the version file
 
-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
+    #   pre-generate various strings
+    triple="${ver}.${rev}${typ}${lev}"
+    vHex="$hex"
+    vShort="${triple}"
+    vLong="${triple} (${tim})"
+    vTeX="This is ${name}, Version ${triple} (${tim})"
+    vGNU="${name} ${triple} (${tim})"
+    vWeb="${name}/${triple}"
+    vSCCS="@(#)${name} ${triple} (${tim})"
+    vRCS="\$Id: ${name} ${triple} ${tim} \$"
+
+    #   determine string out of filename
+    #   (do NOT try to optimize this in any way because of portability)
+    filestr=`echo $file |\
+             tr 'abcdefghijklmnopqrstuvwxyz./%+' \
+                'ABCDEFGHIJKLMNOPQRSTUVWXYZ____' | sed -e 's/-/_/g'`
+    
+    #   create the version file according the the selected language
+    echo "new version: ${vLong}"
+
+    cp /dev/null $file
+    case $opt_l in
+        txt )
+            echo >>$file ""
+            echo >>$file "  ${file} -- Version Information for ${name} (syntax: Text)"
+            echo >>$file "  [automatically generated and maintained by GNU shtool]"
+            echo >>$file ""
+            echo >>$file "  $vTeX"
+            echo >>$file ""
+            ;;
+        c )
+            echo >>$file "/*"
+            echo >>$file "**  ${file} -- Version Information for ${name} (syntax: C/C++)"
+            echo >>$file "**  [automatically generated and maintained by GNU shtool]"
+            echo >>$file "*/"
+            echo >>$file ""
+            echo >>$file "#ifdef _${filestr}_AS_HEADER_"
+            echo >>$file ""
+            echo >>$file "#ifndef _${filestr}_"
+            echo >>$file "#define _${filestr}_"
+            echo >>$file ""
+            echo >>$file "#define ${prefix}VERSION ${vHex}"
+            echo >>$file ""
+            echo >>$file "typedef struct {"
+            echo >>$file "    const int   v_hex;"
+            echo >>$file "    const char *v_short;"
+            echo >>$file "    const char *v_long;"
+            echo >>$file "    const char *v_tex;"
+            echo >>$file "    const char *v_gnu;"
+            echo >>$file "    const char *v_web;"
+            echo >>$file "    const char *v_sccs;"
+            echo >>$file "    const char *v_rcs;"
+            echo >>$file "} ${prefix}version_t;"
+            echo >>$file ""
+            echo >>$file "extern ${prefix}version_t ${prefix}version;"
+            echo >>$file ""
+            echo >>$file "#endif _${filestr}_"
+            echo >>$file ""
+            echo >>$file "#else /* _${filestr}_AS_HEADER_ */"
+            echo >>$file ""
+            echo >>$file "#define _${filestr}_AS_HEADER_"
+            echo >>$file "#include \"${file}\""
+            echo >>$file "#undef  _${filestr}_AS_HEADER_"
+            echo >>$file ""
+            echo >>$file "${prefix}version_t ${prefix}version = {"
+            echo >>$file "    ${vHex},"
+            echo >>$file "    \"${vShort}\","
+            echo >>$file "    \"${vLong}\","
+            echo >>$file "    \"${vTeX}\","
+            echo >>$file "    \"${vGNU}\","
+            echo >>$file "    \"${vWeb}\","
+            echo >>$file "    \"${vSCCS}\","
+            echo >>$file "    \"${vRCS}\""
+            echo >>$file "};"
+            echo >>$file ""
+            echo >>$file "#endif /* _${filestr}_AS_HEADER_ */"
+            echo >>$file ""
+            ;;
+        perl )
+            echo >>$file "/*"
+            echo >>$file "**  ${file} -- Version Information for ${name} (syntax: Perl)"
+            echo >>$file "**  [automatically generated and maintained by GNU shtool]"
+            echo >>$file "*/"
+            echo >>$file ""
+            echo >>$file "my ${prefix}version = {"
+            echo >>$file "    'v_hex'   => ${vHex},"
+            echo >>$file "    'v_short' => \"${vShort}\","
+            echo >>$file "    'v_long'  => \"${vLong}\","
+            echo >>$file "    'v_tex'   => \"${vTeX}\","
+            echo >>$file "    'v_gnu'   => \"${vGNU}\","
+            echo >>$file "    'v_web'   => \"${vWeb}\","
+            echo >>$file "    'v_sccs'  => \"${vSCCS}\","
+            echo >>$file "    'v_rcs'   => \"\\${vRCS}/\""
+            echo >>$file "};"
+            echo >>$file ""
+            echo >>$file "1;"
+            echo >>$file ""
+            ;;
+        * ) echo "$msgprefix:Error: invalid argument to option \`-l': \`$opt_l'" 1>&2
+            exit 1
+            ;;
+    esac
+fi
 

CVSTrac 2.0.1