3
## GNU shtool -- The GNU Portable Shell Tool
4
## Copyright (c) 1994-2000 Ralf S. Engelschall <rse@engelschall.com>
6
## See http://www.gnu.org/software/shtool/ for more information.
7
## See ftp://ftp.gnu.org/gnu/shtool/ for latest version.
9
## Version: 1.5.1 (29-Jul-2000)
10
## Contents: 5/17 available modules
14
## This program is free software; you can redistribute it and/or modify
15
## it under the terms of the GNU General Public License as published by
16
## the Free Software Foundation; either version 2 of the License, or
17
## (at your option) any later version.
19
## This program is distributed in the hope that it will be useful,
20
## but WITHOUT ANY WARRANTY; without even the implied warranty of
21
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
## General Public License for more details.
24
## You should have received a copy of the GNU General Public License
25
## along with this program; if not, write to the Free Software
26
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27
## USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
29
## Notice: Given that you include this file verbatim into your own
30
## source tree, you are justified in saying that it remains separate
31
## from your package, and that this way you are simply just using GNU
32
## shtool. So, in this situation, there is no requirement that your
33
## package itself is licensed under the GNU General Public License in
34
## order to take advantage of GNU shtool.
38
## Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]
40
## Available commands:
41
## echo Print string with optional construct expansion
42
## install Install a program, script or datafile
43
## mkdir Make one or more directories
44
## fixperm Fix file permissions inside a source tree
45
## version Maintain a version information file
47
## Not available commands (because module was not built-in):
48
## mdate Pretty-print modification time of a file or dir
49
## table Pretty-print a field-separated list as a table
50
## prop Display progress with a running propeller
51
## move Move files with simultaneous substitution
52
## mkln Make link with calculation of relative paths
53
## mkshadow Make a shadow tree through symbolic links
54
## tarball Roll distribution tarballs
55
## guessos Simple operating system guesser
56
## arx Extended archive command
57
## slo Separate linker options by library class
58
## scpp Sharing C Pre-Processor
59
## path Deal with program paths
63
echo "$0:Error: invalid command line" 1>&2
64
echo "$0:Hint: run \`$0 -h' for usage" 1>&2
67
if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then
68
echo "This is GNU shtool, version 1.5.1 (29-Jul-2000)"
69
echo "Copyright (c) 1994-2000 Ralf S. Engelschall <rse@engelschall.com>"
70
echo "Report bugs to <bug-shtool@gnu.org>"
72
echo "Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]"
74
echo 'Available global <options>:'
75
echo ' -v, --version display shtool version information'
76
echo ' -h, --help display shtool usage help page (this one)'
77
echo ' -d, --debug display shell trace information'
78
echo ' -r, --recreate recreate this shtool script via shtoolize'
80
echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:'
81
echo ' echo [-n] [-e] [<str> ...]'
82
echo ' install [-v] [-t] [-c] [-C] [-s] [-m<mode>] [-o<owner>] [-g<group>]'
83
echo ' [-e<ext>] <file> [<file> ...] <path>'
84
echo ' mkdir [-t] [-f] [-p] [-m<mode>] <dir> [<dir> ...]'
85
echo ' fixperm [-v] [-t] <path> [<path> ...]'
86
echo ' version [-l<lang>] [-n<name>] [-p<prefix>] [-s<version>] [-e]'
87
echo ' [-i<knob>] [-d<type>] <file>'
89
echo 'Not available <cmd-name> (because module was not built-in):'
90
echo ' mdate [-n] [-z] [-s] [-d] [-f<str>] [-o<spec>] <path>'
91
echo ' table [-F<sep>] [-w<width>] [-c<cols>] [-s<strip>] <str><sep><str>...'
92
echo ' prop [-p<str>]'
93
echo ' move [-v] [-t] [-e] [-p] <src-file> <dst-file>'
94
echo ' mkln [-t] [-f] [-s] <src-path> [<src-path> ...] <dst-path>'
95
echo ' mkshadow [-v] [-t] [-a] <src-dir> <dst-dir>'
96
echo ' tarball [-t] [-v] [-o <tarball>] [-c <prog>] [-d <dir>] [-u'
97
echo ' <user>] [-g <group>] [-e <pattern>] <path> [<path> ...]'
99
echo ' arx [-t] [-C<cmd>] <op> <archive> [<file> ...]'
100
echo ' slo [-p<str>] -- -L<dir> -l<lib> [-L<dir> -l<lib> ...]'
101
echo ' scpp [-v] [-p] [-f<filter>] [-o<ofile>] [-t<tfile>] [-M<mark>]'
102
echo ' [-D<dname>] [-C<cname>] <file> [<file> ...]'
103
echo ' path [-s] [-r] [-d] [-b] [-m] [-p<path>] <str> [<str> ...]'
107
if [ ".$1" = ".-v" -o ".$1" = ."--version" ]; then
108
echo "GNU shtool 1.5.1 (29-Jul-2000)"
111
if [ ".$1" = ".-r" -o ".$1" = ."--recreate" ]; then
112
shtoolize -oetc/shtool echo install mkdir fixperm version
115
if [ ".$1" = ".-d" -o ".$1" = ."--debug" ]; then
119
name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'`
121
echo|install|mkdir|fixperm|version )
122
# implicit tool command selection
126
# explicit tool command selection
136
## DISPATCH INTO SCRIPT PROLOG
142
str_usage="[-n] [-e] [<str> ...]"
150
str_usage="[-v] [-t] [-c] [-C] [-s] [-m<mode>] [-o<owner>] [-g<group>] [-e<ext>] <file> [<file> ...] <path>"
152
opt_spec="v.t.c.C.s.m:o:g:e:"
165
str_usage="[-t] [-f] [-p] [-m<mode>] <dir> [<dir> ...]"
175
str_usage="[-v] [-t] <path> [<path> ...]"
183
str_usage="[-l<lang>] [-n<name>] [-p<prefix>] [-s<version>] [-e] [-i<knob>] [-d<type>] <file>"
185
opt_spec="l:n:p:s:i:e.d:"
195
echo "$0:Error: unknown option \`$tool'" 2>&1
196
echo "$0:Hint: run \`$0 -h' for usage" 2>&1
200
echo "$0:Error: unknown command \`$tool'" 2>&1
201
echo "$0:Hint: run \`$0 -h' for usage" 2>&1
207
## COMMON UTILITY CODE
210
# determine name of tool
211
if [ ".$tool" != . ]; then
212
# used inside shtool script
214
toolcmdhelp="shtool $tool"
215
msgprefix="shtool:$tool"
217
# used as standalone script
220
msgprefix="$str_tool"
223
# parse argument specification string
224
eval `echo $arg_spec |\
225
sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'`
227
# parse option specification string
228
eval `echo h.$opt_spec |\
229
sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'`
231
# interate over argument line
233
while [ $# -gt 0 ]; do
234
# special option stops processing
235
if [ ".$1" = ".--" ]; then
240
# determine option and argument
242
if [ ".$opt_PREV" != . ]; then
243
# merge previous seen option with argument
249
# split argument into option and argument
253
sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \
254
-e 's/";\(.*\)$/"; opt_ARG="\1"/'`
257
opt_OPT=`echo "x$1" | cut -c3-`
269
# determine whether option needs an argument
270
eval "opt_MODE=\$opt_MODE_${opt_OPT}"
271
if [ ".$opt_ARG" = . -a ".$opt_ARG_OK" != .yes ]; then
272
if [ ".$opt_MODE" = ".:" -o ".$opt_MODE" = ".+" ]; then
282
eval "opt_${opt_OPT}=yes"
285
# option with argument (multiple occurances override)
286
eval "opt_${opt_OPT}=\"\$opt_ARG\""
289
# option with argument (multiple occurances append)
290
eval "opt_${opt_OPT}=\"\$opt_${opt_OPT} \$opt_ARG\""
293
echo "$msgprefix:Error: unknown option: \`-$opt_OPT'" 1>&2
294
echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
299
if [ ".$opt_PREV" != . ]; then
300
echo "$msgprefix:Error: missing argument to option \`-$opt_PREV'" 1>&2
301
echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
305
# process help option
306
if [ ".$opt_h" = .yes ]; then
307
echo "Usage: $toolcmdhelp $str_usage"
311
# complain about incorrect number of arguments
314
if [ $# -ne $arg_NUMS ]; then
315
echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2
316
echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
321
if [ $# -lt $arg_NUMS ]; then
322
echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2
323
echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
329
# establish a temporary file on request
330
if [ ".$gen_tmpfile" = .yes ]; then
331
if [ ".$TMPDIR" != . ]; then
333
elif [ ".$TEMPDIR" != . ]; then
338
tmpfile="$tmpdir/.shtool.$$"
339
rm -f $tmpfile >/dev/null 2>&1
344
## DISPATCH INTO SCRIPT BODY
351
## echo -- Print string with optional construct expansion
352
## Copyright (c) 1998-2000 Ralf S. Engelschall <rse@engelschall.com>
353
## Originally written for WML as buildinfo
358
# check for broken escape sequence expansion
360
bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'`
361
if [ ".$bytes" != .3 ]; then
362
bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'`
363
if [ ".$bytes" = .3 ]; then
368
# check for existing -n option (to suppress newline)
370
bytes=`echo -n 123 2>/dev/null | wc -c | awk '{ printf("%s", $1); }'`
371
if [ ".$bytes" = .3 ]; then
375
# determine terminal bold sequence
378
if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[Bb]'`" != . ]; then
380
# for the most important terminal types we directly know the sequences
381
xterm|xterm*|vt220|vt220*)
382
term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' </dev/null 2>/dev/null`
383
term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' </dev/null 2>/dev/null`
386
term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' </dev/null 2>/dev/null`
387
term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' </dev/null 2>/dev/null`
389
# for all others, we try to use a possibly existing `tput' or `tcout' utility
391
paths=`echo $PATH | sed -e 's/:/ /g'`
392
for tool in tput tcout; do
393
for dir in $paths; do
394
if [ -r "$dir/$tool" ]; then
395
for seq in bold md smso; do # 'smso' is last
396
bold="`$dir/$tool $seq 2>/dev/null`"
397
if [ ".$bold" != . ]; then
402
if [ ".$term_bold" != . ]; then
403
for seq in sgr0 me rmso reset; do # 'reset' is last
404
norm="`$dir/$tool $seq 2>/dev/null`"
405
if [ ".$norm" != . ]; then
414
if [ ".$term_bold" != . -a ".$term_norm" != . ]; then
420
if [ ".$term_bold" = . -o ".$term_norm" = . ]; then
421
echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2
425
# determine user name
427
if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[uU]'`" != . ]; then
429
if [ ".$username" = . ]; then
431
if [ ".$username" = . ]; then
432
username="`(whoami) 2>/dev/null |\
433
awk '{ printf("%s", $1); }'`"
434
if [ ".$username" = . ]; then
435
username="`(who am i) 2>/dev/null |\
436
awk '{ printf("%s", $1); }'`"
437
if [ ".$username" = . ]; then
447
if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%U'`" != . ]; then
448
userid="`(id -u) 2>/dev/null`"
449
if [ ".$userid" = . ]; then
450
str="`(id) 2>/dev/null`"
451
if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then
452
userid=`echo $str | sed -e 's/^uid[ ]*=[ ]*//' -e 's/(.*//'`
454
if [ ".$userid" = . ]; then
455
userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
456
sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
457
if [ ".$userid" = . ]; then
458
userid=`(ypcat passwd) 2>/dev/null |
459
egrep "^${username}:" | \
460
sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
461
if [ ".$userid" = . ]; then
469
# determine host name
471
if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%h'`" != . ]; then
472
hostname="`(uname -n) 2>/dev/null |\
473
awk '{ printf("%s", $1); }'`"
474
if [ ".$hostname" = . ]; then
475
hostname="`(hostname) 2>/dev/null |\
476
awk '{ printf("%s", $1); }'`"
477
if [ ".$hostname" = . ]; then
483
domainname=".`echo $hostname | cut -d. -f2-`"
484
hostname="`echo $hostname | cut -d. -f1`"
489
# determine domain name
491
if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%d'`" != . ]; then
492
if [ ".$domainname" = . ]; then
493
if [ -f /etc/resolv.conf ]; then
494
domainname="`egrep '^[ ]*domain' /etc/resolv.conf | head -1 |\
495
sed -e 's/.*domain//' \
496
-e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
497
-e 's/^\.//' -e 's/^/./' |\
498
awk '{ printf("%s", $1); }'`"
499
if [ ".$domainname" = . ]; then
500
domainname="`egrep '^[ ]*search' /etc/resolv.conf | head -1 |\
501
sed -e 's/.*search//' \
502
-e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
503
-e 's/ .*//' -e 's/ .*//' \
504
-e 's/^\.//' -e 's/^/./' |\
505
awk '{ printf("%s", $1); }'`"
511
# determine current time
516
if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[DMYm]'`" != . ]; then
517
time_day=`date '+%d'`
518
time_month=`date '+%m'`
519
time_year=`date '+%Y' 2>/dev/null`
520
if [ ".$time_year" = . ]; then
521
time_year=`date '+%y'`
523
[5-9][0-9]) time_year="19$time_year" ;;
524
[0-4][0-9]) time_year="20$time_year" ;;
528
1|01) time_monthname='Jan' ;;
529
2|02) time_monthname='Feb' ;;
530
3|03) time_monthname='Mar' ;;
531
4|04) time_monthname='Apr' ;;
532
5|05) time_monthname='May' ;;
533
6|06) time_monthname='Jun' ;;
534
7|07) time_monthname='Jul' ;;
535
8|08) time_monthname='Aug' ;;
536
9|09) time_monthname='Sep' ;;
537
10) time_monthname='Oct' ;;
538
11) time_monthname='Nov' ;;
539
12) time_monthname='Dec' ;;
543
# expand special ``%x'' constructs
544
if [ ".$opt_e" = .yes ]; then
545
text=`echo $seo "$text" |\
546
sed -e "s/%B/${term_bold}/g" \
547
-e "s/%b/${term_norm}/g" \
548
-e "s/%u/${username}/g" \
549
-e "s/%U/${userid}/g" \
550
-e "s/%h/${hostname}/g" \
551
-e "s/%d/${domainname}/g" \
552
-e "s/%D/${time_day}/g" \
553
-e "s/%M/${time_month}/g" \
554
-e "s/%Y/${time_year}/g" \
555
-e "s/%m/${time_monthname}/g" 2>/dev/null`
559
if [ .$opt_n = .no ]; then
562
# the harder part: echo -n is best, because
563
# awk may complain about some \xx sequences.
564
if [ ".$minusn" != . ]; then
565
echo $seo $minusn "$text"
567
echo dummy | awk '{ printf("%s", TEXT); }' TEXT="$text"
574
## install -- Install a program, script or datafile
575
## Copyright (c) 1997-2000 Ralf S. Engelschall <rse@engelschall.com>
576
## Originally written for shtool
579
# determine source(s) and destination
582
while [ $# -gt 1 ]; do
588
# type check for destination
590
if [ -d $dstpath ]; then
591
dstpath=`echo "$dstpath" | sed -e 's:/$::'`
595
# consistency check for destination
596
if [ $argc -gt 2 -a $dstisdir = 0 ]; then
597
echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2
601
# iterate over all source(s)
605
# If destination is a directory, append the input filename
606
if [ $dstisdir = 1 ]; then
607
dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'`
611
# Add a possible extension to src and dst
612
if [ ".$opt_e" != . ]; then
617
# Check for correct arguments
618
if [ ".$src" = ".$dst" ]; then
619
echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2
622
if [ -d "$src" ]; then
623
echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2
627
# Make a temp file name in the destination directory
629
sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \
630
-e "s;\$;/#INST@$$#;"`
633
if [ ".$opt_v" = .yes ]; then
634
echo "$src -> $dst" 1>&2
637
# Copy or move the file name to the temp name
638
# (because we might be not allowed to change the source)
639
if [ ".$opt_C" = .yes ]; then
642
if [ ".$opt_c" = .yes ]; then
643
if [ ".$opt_t" = .yes ]; then
644
echo "cp $src $dsttmp" 1>&2
646
cp $src $dsttmp || exit $?
648
if [ ".$opt_t" = .yes ]; then
649
echo "mv $src $dsttmp" 1>&2
651
mv $src $dsttmp || exit $?
654
# Adjust the target file
655
# (we do chmod last to preserve setuid bits)
656
if [ ".$opt_s" = .yes ]; then
657
if [ ".$opt_t" = .yes ]; then
658
echo "strip $dsttmp" 1>&2
660
strip $dsttmp || exit $?
662
if [ ".$opt_o" != . ]; then
663
if [ ".$opt_t" = .yes ]; then
664
echo "chown $opt_o $dsttmp" 1>&2
666
chown $opt_o $dsttmp || exit $?
668
if [ ".$opt_g" != . ]; then
669
if [ ".$opt_t" = .yes ]; then
670
echo "chgrp $opt_g $dsttmp" 1>&2
672
chgrp $opt_g $dsttmp || exit $?
674
if [ ".$opt_m" != . ]; then
675
if [ ".$opt_t" = .yes ]; then
676
echo "chmod $opt_m $dsttmp" 1>&2
678
chmod $opt_m $dsttmp || exit $?
681
# Determine whether to do a quick install
682
# (has to be done _after_ the strip was already done)
684
if [ ".$opt_C" = .yes ]; then
686
if cmp -s $src $dst; then
692
# Finally install the file to the real destination
693
if [ $quick = yes ]; then
694
if [ ".$opt_t" = .yes ]; then
695
echo "rm -f $dsttmp" 1>&2
699
if [ ".$opt_t" = .yes ]; then
700
echo "rm -f $dst && mv $dsttmp $dst" 1>&2
702
rm -f $dst && mv $dsttmp $dst
709
## mkdir -- Make one or more directories
710
## Copyright (c) 1996-2000 Ralf S. Engelschall <rse@engelschall.com>
711
## Originally written for public domain by Noah Friedman <friedman@prep.ai.mit.edu>
712
## Cleaned up and enhanced for shtool
716
for p in ${1+"$@"}; do
717
# if the directory already exists...
719
if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then
720
echo "$msgprefix:Error: directory already exists: $p" 1>&2
727
# if the directory has to be created...
728
if [ ".$opt_p" = .no ]; then
729
if [ ".$opt_t" = .yes ]; then
732
mkdir $p || errstatus=$?
734
# the smart situation
735
set fnord `echo ":$p" |\
742
for d in ${1+"$@"}; do
743
pathcomp="$pathcomp$d"
745
-* ) pathcomp="./$pathcomp" ;;
747
if [ ! -d "$pathcomp" ]; then
748
if [ ".$opt_t" = .yes ]; then
749
echo "mkdir $pathcomp" 1>&2
751
mkdir $pathcomp || errstatus=$?
752
if [ ".$opt_m" != . ]; then
753
if [ ".$opt_t" = .yes ]; then
754
echo "chmod $opt_m $pathcomp" 1>&2
756
chmod $opt_m $pathcomp || errstatus=$?
759
pathcomp="$pathcomp/"
768
## fixperm -- Fix file permissions inside a source tree
769
## Copyright (c) 1996-2000 Ralf S. Engelschall <rse@engelschall.com>
770
## Originally written for ePerl
775
# check whether the test command supports the -x option
776
if [ -x /bin/sh ] 2>/dev/null; then
784
for file in `find $p -depth -print`; do
785
if [ -f $file ]; then
786
if [ $minusx $file ]; then
787
if [ ".$opt_v" = .yes ]; then
788
echo "-rwxrwxr-x $file" 2>&1
790
if [ ".$opt_t" = .yes ]; then
791
echo "chmod 775 $file" 2>&1
795
if [ ".$opt_v" = .yes ]; then
796
echo "-rw-rw-r-- $file" 2>&1
798
if [ ".$opt_t" = .yes ]; then
799
echo "chmod 664 $file" 2>&1
805
if [ -d $file ]; then
806
if [ ".$opt_v" = .yes ]; then
807
echo "drwxrwxr-x $file" 2>&1
809
if [ ".$opt_t" = .yes ]; then
810
echo "chmod 775 $file" 2>&1
815
if [ ".$opt_v" = .yes ]; then
816
echo "?????????? $file" 2>&1
824
## version -- Maintain a version information file
825
## Copyright (c) 1994-2000 Ralf S. Engelschall <rse@engelschall.com>
826
## Originally written for ePerl, rewritten from scratch for shtool
831
# determine prefix and name
835
# determine current version
837
if [ ".$triple" != . ]; then
839
if [ ".`echo $triple | grep '[0-9]*.[0-9]*[sabp.][0-9]*'`" = . ]; then
840
echo "$msgprefix:Error: invalid argument to option \`-s': \`$opt_s'" 1>&2
843
eval `echo $triple |\
844
sed -e 's%\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\).*%\
845
ver="\1";rev="\2";typ="\3";lev="\4"%'`
847
elif [ -r $file ]; then
848
# determine triple from given file
849
eval `grep 'Version [0-9]*.[0-9]*[sabp.][0-9]* ([0-9]*-[a-zA-Z]*-[0-9]*)' $file |\
850
head -1 | sed -e 's%.*Version \([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\) (\([0-9]*-[a-zA-Z]*-[0-9]*\)).*%\
851
ver="\1";rev="\2";typ="\3";lev="\4";tim="\5"%'`
853
# intialise to first version
861
# determine new version in batch
862
if [ ".$opt_i" != . ]; then
864
v ) ver=`expr $ver + 1`
868
r ) rev=`expr $rev + 1`
871
l ) lev=`expr $lev + 1`
873
* ) echo "$msgprefix:Error: invalid argument to option \`-i': \`$opt_i'" 1>&2
880
# determine new version interactively
881
if [ ".$opt_e" = .yes ]; then
882
echo "old version: ${ver}.${rev}${typ}${lev}"
884
echo dummy | awk '{ printf("new version: "); }'
887
[0-9]*.[0-9]*[sabp.][0-9]* )
889
* ) echo "$msgprefix:Error: invalid version string entered: \`$triple'" 1>&2
895
eval `echo $triple |\
896
sed -e 's%^\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\)$%\
897
ver="\1";rev="\2";typ="\3";lev="\4"%'`
901
# determine hexadecimal and libtool value of version
903
a ) typnum=0; levnum=$lev ;;
904
b ) typnum=1; levnum=$lev ;;
905
p | . ) typnum=2; levnum=$lev ;;
906
s ) typnum=15; levnum=255 ;; # snapshots are special
908
hex=`echo "$ver:$rev:$typnum:$levnum" |\
909
awk -F: '{ printf("0x%x%02x%1x%02x", $1, $2, $3, $4); }' |\
910
tr 'abcdef' 'ABCDEF'`
911
ltv=`echo "$ver:$rev:$typnum:$levnum" |\
912
awk -F: '{ printf("%d:%d", $1*10 + $2, $3*10 + $4); }'`
915
if [ ".$tim" = .calc ]; then
918
year=`date '+%Y' 2>/dev/null`
919
if [ ".$time_year" = . ]; then
922
[5-9][0-9]) year="19$year" ;;
923
[0-4][0-9]) year="20$year" ;;
940
tim="${day}-${month}-${year}"
943
# perform result actions
945
if [ ".$opt_i" != . ]; then
947
elif [ ".$opt_e" = .yes ]; then
949
elif [ ".$opt_s" != . ]; then
952
if [ ".$mode" = .show ]; then
953
# just display the current version
956
echo "${ver}.${rev}${typ}${lev}"
959
echo "${ver}.${rev}${typ}${lev} ($tim)"
967
* ) echo "$msgprefix:Error: invalid argument to option \`-d': \`$opt_d'" 1>&2
972
# update the version file
974
# pre-generate various strings
975
triple="${ver}.${rev}${typ}${lev}"
978
vLong="${triple} (${tim})"
979
vTeX="This is ${name}, Version ${triple} (${tim})"
980
vGNU="${name} ${triple} (${tim})"
981
vWeb="${name}/${triple}"
982
vSCCS="@(#)${name} ${triple} (${tim})"
983
vRCS="\$Id: ${name} ${triple} (${tim}) \$"
985
# determine string out of filename
986
# (do NOT try to optimize this in any way because of portability)
987
filestr=`echo $file |\
988
tr 'abcdefghijklmnopqrstuvwxyz./%+' \
989
'ABCDEFGHIJKLMNOPQRSTUVWXYZ____' | sed -e 's/-/_/g'`
991
# generate uppercase prefix
992
prefixupper=`echo $prefix |\
993
tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
995
# create the version file according the the selected language
996
echo "new version: ${vLong}"
1002
echo >>$file " ${file} -- Version Information for ${name} (syntax: Text)"
1003
echo >>$file " [automatically generated and maintained by GNU shtool]"
1005
echo >>$file " $vTeX"
1010
echo >>$file "** ${file} -- Version Information for ${name} (syntax: C/C++)"
1011
echo >>$file "** [automatically generated and maintained by GNU shtool]"
1014
echo >>$file "#ifdef _${filestr}_AS_HEADER_"
1016
echo >>$file "#ifndef _${filestr}_"
1017
echo >>$file "#define _${filestr}_"
1019
echo >>$file "#define ${prefixupper}VERSION ${vHex}"
1021
echo >>$file "typedef struct {"
1022
echo >>$file " const int v_hex;"
1023
echo >>$file " const char *v_short;"
1024
echo >>$file " const char *v_long;"
1025
echo >>$file " const char *v_tex;"
1026
echo >>$file " const char *v_gnu;"
1027
echo >>$file " const char *v_web;"
1028
echo >>$file " const char *v_sccs;"
1029
echo >>$file " const char *v_rcs;"
1030
echo >>$file "} ${prefix}version_t;"
1032
echo >>$file "extern ${prefix}version_t ${prefix}version;"
1034
echo >>$file "#endif /* _${filestr}_ */"
1036
echo >>$file "#else /* _${filestr}_AS_HEADER_ */"
1038
echo >>$file "#define _${filestr}_AS_HEADER_"
1039
echo >>$file "#include \"${file}\""
1040
echo >>$file "#undef _${filestr}_AS_HEADER_"
1042
echo >>$file "${prefix}version_t ${prefix}version = {"
1043
echo >>$file " ${vHex},"
1044
echo >>$file " \"${vShort}\","
1045
echo >>$file " \"${vLong}\","
1046
echo >>$file " \"${vTeX}\","
1047
echo >>$file " \"${vGNU}\","
1048
echo >>$file " \"${vWeb}\","
1049
echo >>$file " \"${vSCCS}\","
1050
echo >>$file " \"${vRCS}\""
1053
echo >>$file "#endif /* _${filestr}_AS_HEADER_ */"
1058
echo >>$file "## ${file} -- Version Information for ${name} (syntax: Perl)"
1059
echo >>$file "## [automatically generated and maintained by GNU shtool]"
1062
echo >>$file "my \$${prefix}version = {"
1063
echo >>$file " 'v_hex' => ${vHex},"
1064
echo >>$file " 'v_short' => \"${vShort}\","
1065
echo >>$file " 'v_long' => \"${vLong}\","
1066
echo >>$file " 'v_tex' => \"${vTeX}\","
1067
echo >>$file " 'v_gnu' => \"${vGNU}\","
1068
echo >>$file " 'v_web' => \"${vWeb}\","
1069
echo >>$file " 'v_sccs' => \"${vSCCS}\","
1070
echo >>$file " 'v_rcs' => \"\\${vRCS}/\""
1078
echo >>$file "## ${file} -- Version Information for ${name} (syntax: Python)"
1079
echo >>$file "## [automatically generated and maintained by GNU shtool]"
1082
echo >>$file "class ${prefix}version:"
1083
echo >>$file " v_hex = ${vHex}"
1084
echo >>$file " v_short = \"${vShort}\""
1085
echo >>$file " v_long = \"${vLong}\""
1086
echo >>$file " v_tex = \"${vTeX}\""
1087
echo >>$file " v_gnu = \"${vGNU}\""
1088
echo >>$file " v_web = \"${vWeb}\""
1089
echo >>$file " v_sccs = \"${vSCCS}\""
1090
echo >>$file " v_rcs = \"${vRCS}\""
1093
* ) echo "$msgprefix:Error: invalid argument to option \`-l': \`$opt_l'" 1>&2