--- sh.version 2000/06/30 16:27:41 1.22
+++ sh.version 2000/07/01 12:13:38 1.23
@@ -1,7 +1,7 @@
##
## version -- Maintain a version information file
## Copyright (c) 1994-2000 Ralf S. Engelschall <rse@engelschall.com>
-## Originally written for ePerl
+## Originally written for ePerl, rewritten from scratch for shtool
##
## 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
@@ -24,7 +24,7 @@
arg_spec="1="
opt_spec="l:n:p:s:i:e.d:"
opt_l="txt"
-opt_n=""
+opt_n="unknown"
opt_p=""
opt_s=""
opt_e="no"
@@ -35,15 +35,9 @@
file="$1"
-# determine prefix from name and vice versa
+# determine prefix and name
name="$opt_n"
prefix="$opt_p"
-if [ ".$prefix" = . -a ".$name" != . ]; then
- prefix="$name"
-fi
-if [ ".$name" = . -a ".$prefix" != . ]; then
- name="$prefix"
-fi
# determine current version
triple="$opt_s"
@@ -53,22 +47,15 @@
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 }'`
+ eval `echo $triple |\
+ sed -e 's%\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\).*%\
+ ver="\1";rev="\2";typ="\3";lev="\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 }'`
+ eval `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]*\)).*%\
+ ver="\1";rev="\2";typ="\3";lev="\4";tim="\5"%'`
else
# intialise to first version
ver=0
@@ -103,32 +90,32 @@
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
+ case $triple in
+ [0-9]*.[0-9]*[sabp.][0-9]* )
+ ;;
+ * ) echo "$msgprefix:Error: invalid version string entered: \`$triple'" 1>&2
+ continue
+ ;;
+ esac
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 }'`
+ eval `echo $triple |\
+ sed -e 's%^\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\)$%\
+ ver="\1";rev="\2";typ="\3";lev="\4"%'`
tim=calc
fi
# 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
+ a ) typnum=0; levnum=$lev ;;
+ b ) typnum=1; levnum=$lev ;;
+ p | . ) typnum=2; levnum=$lev ;;
+ s ) typnum=15; levnum=255 ;; # snapshots are special
esac
hex=`echo "$ver:$rev:$typnum:$levnum" |\
- awk -F: '{ printf("0x%d%02d%1d%02d", $1, $2, $3, $4); }'`
+ awk -F: '{ printf("0x%X%02X%1X%02X", $1, $2, $3, $4); }'`
ltv=`echo "$ver:$rev:$typnum:$levnum" |\
- awk -F: '{ printf("%d:%d", $1*10 + $2, $3*10 + $2); }'`
+ awk -F: '{ printf("%d:%d", $1*10 + $2, $3*10 + $4); }'`
# determine date
if [ ".$tim" = .calc ]; then
@@ -171,12 +158,12 @@
if [ ".$mode" = .show ]; then
# just display the current version
case $opt_d in
- long )
- echo "${ver}.${rev}${typ}${lev} ($tim)"
- ;;
short )
echo "${ver}.${rev}${typ}${lev}"
;;
+ long )
+ echo "${ver}.${rev}${typ}${lev} ($tim)"
+ ;;
libtool )
echo "${ltv}"
;;
@@ -199,13 +186,17 @@
vGNU="${name} ${triple} (${tim})"
vWeb="${name}/${triple}"
vSCCS="@(#)${name} ${triple} (${tim})"
- vRCS="\$Id: ${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'`
+
+ # generate uppercase prefix
+ prefixupper=`echo $prefix |\
+ tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
# create the version file according the the selected language
echo "new version: ${vLong}"
@@ -231,7 +222,7 @@
echo >>$file "#ifndef _${filestr}_"
echo >>$file "#define _${filestr}_"
echo >>$file ""
- echo >>$file "#define ${prefix}VERSION ${vHex}"
+ echo >>$file "#define ${prefixupper}VERSION ${vHex}"
echo >>$file ""
echo >>$file "typedef struct {"
echo >>$file " const int v_hex;"
@@ -269,12 +260,12 @@
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 "## ${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 "my \$${prefix}version = {"
echo >>$file " 'v_hex' => ${vHex},"
echo >>$file " 'v_short' => \"${vShort}\","
echo >>$file " 'v_long' => \"${vLong}\","
|