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