1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
#!/bin/sh -
##
## NEWVERS -- setup new program version file
## Copyright (c) 1994-1997 Ralf S. Engelschall, <rse@engelschall.com>
##
## NOTICE: This intentionally written in Bourne-Shell instead
## of my preferred language Perl because this is also
## used as a version display tool in "./configire" steps...
##
VERSION="2.2.2"
DATE="02-06-1997"
# print version information line
print_version () {
echo "This is NEWVERS, Version $VERSION ($DATE)"
}
# give general help information
print_help () {
cat <<'EOT'
NEWVERS -- generate/maintain a version information file
Copyright (c) 1994-1997 Ralf S. Engelschall, <rse@engelschall.com>
NEWVERS will create and update a version information file,
which can be setup in either plain text or the C or Perl language.
Examples:
$ newvers -m txt -p TestProg version.txt
$ newvers -m c -p TestProg version.c
$ newvers -m perl -p TestProg version.pl
EOT
}
# give usage information
print_usage () {
cat <<'EOT'
Usage: newvers [options] versionfile
Options are:
-l<lang> set language to one of "txt", "c" or "perl"
-p<progname> set program name
-r<v>.<r>[.pb]<p> set release version string
-i{v|r|P|p|b|a|s} increase version, revision or {alpha,batch,patch,snap}level
-d display current version only
-D display current version only (incl. date)
-V print NEWVERS version
-h print help page
EOT
}
# process the argument line
LANGUAGE=unknown
PROGNAME="-UNKNOWN-"
VERSION=unknown
REPORT=NO
REPORTFULL=NO
INCREASE=P
# fallback if "getopt" is not available on system
getopt=getopt
eval "$getopt" >/dev/null 2>&1
if [ $? -ne 0 ]; then
rm -f /tmp/getopt.c >/dev/null 2>&1
cat >/tmp/getopt.c <<EOT
#include <stdio.h>
main(argc, argv)
int argc;
char *argv[];
{
extern int optind;
extern char *optarg;
int c;
int status = 0;
optind = 2; /* Past the program name and the option letters. */
while ((c = getopt(argc, argv, argv[1])) != EOF)
switch (c) {
case '?':
status = 1; /* getopt routine gave message */
break;
default:
if (optarg != NULL)
printf(" -%c %s", c, optarg);
else
printf(" -%c", c);
break;
}
printf(" --");
for (; optind < argc; optind++)
printf(" %s", argv[optind]);
printf("\n");
exit(status);
}
EOT
cc -o /tmp/getopt /tmp/getopt.c
getopt=/tmp/getopt
fi
set -- `$getopt l:p:r:i:dDVh $*`
if [ $? != 0 ]; then
print_usage
exit 2
fi
rm -f /tmp/getopt >/dev/null 2>&1
for opt in $*; do
case $opt in
-l) LANGUAGE=$2; shift; shift ;;
-p) PROGNAME=$2; shift; shift ;;
-r) VERSION=$2; shift; shift ;;
-i) INCREASE=$2; shift; shift ;;
-d) REPORT=YES; shift ;;
-D) REPORT=YES; REPORTFULL=YES; shift ;;
-V) print_version; exit 0 ;;
-h) print_help; print_usage; exit 0 ;;
--) shift; break ;;
esac
done
case $# in
1) VERSIONFILE=$1 ;;
*) print_usage; exit 1 ;;
esac
# determine language
if [ "$LANGUAGE" = "unknown" ]; then
case $VERSIONFILE in
*.txt ) LANGUAGE=txt ;;
*.c ) LANGUAGE=c ;;
*.pl | *.pm ) LANGUAGE=perl ;;
* ) echo "Unkown language type"; exit 1 ;;
esac
fi
# determine version
if [ "$VERSION" = "unknown" ]; then
if [ -r "$VERSIONFILE" ]; then
# grep out current information
id=`grep 'Version [0-9]*.[0-9]*[.abps][0-9]* ([0-9]*-[0-9]*-[0-9]*)' $VERSIONFILE | \
head -1 | \
sed -e 's%.*Version \([0-9]*\)\.\([0-9]*\)\([.abps]\)\([0-9]*\) (\([0-9]*-[0-9]*-[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`
bplevel=0
;;
v )
version=`expr $version + 1`
revision=0
bplevel=0
;;
esac
date=`date '+%d-%m-19%y'`
fi
else
# intialise to first version
version=0
revision=5
bptype=b
bplevel=0
date=`date '+%d-%m-19%y'`
fi
else
# take given version
VERSION=`echo $VERSION | sed -e 's%\([0-9]*\)\.\([0-9]*\)\([.abps]\)\([0-9]*\).*%\1:\2:\3:\4%'`
version=`echo $VERSION | awk -F: '{ print $1 }'`
revision=`echo $VERSION | awk -F: '{ print $2 }'`
bptype=`echo $VERSION | awk -F: '{ print $3 }'`
bplevel=`echo $VERSION | awk -F: '{ print $4 }'`
date=`date '+%d-%m-19%y'`
fi
if [ $REPORT = YES ]; then
if [ $REPORTFULL = YES ]; then
echo "$version.$revision$bptype$bplevel ($date)"
else
echo "$version.$revision$bptype$bplevel"
fi
exit 0;
else
echo "new version: $version.$revision$bptype$bplevel ($date)"
fi
# create date string
year=`date '+19%y'`
month=`date '+%m'`
day=`date '+%d'`
# create the version file according the the selected language
tmpfile="/tmp/newvers.tmp.$$"
rm -f $tmpfile
case $LANGUAGE in
txt )
cat >$tmpfile <<'EOF'
This is @PROGNAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)
EOF
;;
c )
cat >$tmpfile <<'EOF'
/* !! This file was automatically generated by NEWVERS !! */
/* for logfiles, etc. */
char @PROGNAME@_Version[] =
"@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
/* interactive 'hello' string to identify us to the user */
char @PROGNAME@_Hello[] =
"This is @PROGNAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
/* a GNU --version output */
char @PROGNAME@_GNUVersion[] =
"@PROGNAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
/* a UNIX what(1) id string */
char @PROGNAME@_WhatID[] =
"@(#)@PROGNAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
/* a RCS ident(1) id string */
char @PROGNAME@_RCSIdentID[] =
"$Id: @PROGNAME@ @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ @DAY@-@MONTH@-@YEAR@ $";
/* a WWW id string */
char @PROGNAME@_WebID[] =
"@PROGNAME@/@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
/* a plain id string */
char @PROGNAME@_PlainID[] =
"@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
EOF
;;
perl )
cat >$tmpfile <<'EOF'
# !! This file was automatically generated by NEWVERS !!
package Vers;
# for logfiles, etc.
$@PROGNAME@_Version =
"@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
# interactive 'hello' string to identify us to the user
$@PROGNAME@_Hello =
"This is @PROGNAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
# a GNU --version output
$@PROGNAME@_GNUVersion =
"@PROGNAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
# a UNIX what(1) id string
$@PROGNAME@_WhatID =
"@(#)@PROGNAME@ Version @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ (@DAY@-@MONTH@-@YEAR@)";
# a RCS ident(1) id string
$@PROGNAME@_RCSIdentID =
"\$Id: @PROGNAME@ @VERSION@.@REVISION@@BPTYPE@@BPLEVEL@ @DAY@-@MONTH@-@YEAR@ \$";
# a WWW id string
$@PROGNAME@_WebID =
"@PROGNAME@/@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
# a plain id string
$@PROGNAME@_PlainID =
"@VERSION@.@REVISION@@BPTYPE@@BPLEVEL@";
1;
EOF
;;
* ) print_usage; exit 1
;;
esac
rm -f $VERSIONFILE
# now create the version file
sed \
-e "s|@PROGNAME@|$PROGNAME|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 >$VERSIONFILE
rm -f $tmpfile
##EOF##
|