Index: ossp-pkg/shtool/ChangeLog RCS File: /v/ossp/cvs/ossp-pkg/shtool/ChangeLog,v rcsdiff -q -kk '-r1.157' '-r1.158' -u '/v/ossp/cvs/ossp-pkg/shtool/ChangeLog,v' 2>/dev/null --- ChangeLog 2001/06/14 18:42:36 1.157 +++ ChangeLog 2001/06/14 19:02:54 1.158 @@ -9,6 +9,13 @@ ChangeLog + Changes between 1.5.4 and 1.6.0 (14-Jun-2001 to xx-Jun-2001): + + *) Add new `shtool subst [-v] [-t] [-n] [-s] [-i] [-b] + [-e] [-f] [] [...]' command. This + is a useful wrapper around sed(1). + [Ralf S. Engelschall] + Changes between 1.5.3 and 1.5.4 (19-Apr-2001 to 14-Jun-2001): *) Removed numerious trailing whitespaces from source files. Index: ossp-pkg/shtool/Makefile.in RCS File: /v/ossp/cvs/ossp-pkg/shtool/Makefile.in,v rcsdiff -q -kk '-r1.42' '-r1.43' -u '/v/ossp/cvs/ossp-pkg/shtool/Makefile.in,v' 2>/dev/null --- Makefile.in 2001/06/14 14:24:16 1.42 +++ Makefile.in 2001/06/14 19:02:54 1.43 @@ -55,6 +55,7 @@ sh.mkshadow \ sh.fixperm \ sh.tarball \ + sh.subst \ sh.guessos \ sh.arx \ sh.slo \ Index: ossp-pkg/shtool/README RCS File: /v/ossp/cvs/ossp-pkg/shtool/README,v rcsdiff -q -kk '-r1.79' '-r1.80' -u '/v/ossp/cvs/ossp-pkg/shtool/README,v' 2>/dev/null --- README 2001/06/14 18:42:36 1.79 +++ README 2001/06/14 19:02:54 1.80 @@ -33,6 +33,7 @@ mkshadow Make a shadow tree fixperm Fix file permissions inside a source tree tarball Roll distribution tarballs + subst Apply sed(1) substitution operations guessos Simple OS/platform guesser arx Extended archive command slo Separate linker options by library class Index: ossp-pkg/shtool/sh.common RCS File: /v/ossp/cvs/ossp-pkg/shtool/sh.common,v co -q -kk -p'1.18' '/v/ossp/cvs/ossp-pkg/shtool/sh.common,v' | diff -u /dev/null - -L'ossp-pkg/shtool/sh.common' 2>/dev/null --- ossp-pkg/shtool/sh.common +++ - 2024-05-12 01:43:35.332174030 +0200 @@ -0,0 +1,160 @@ +## +## 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 +## License as published by the Free Software Foundation; either version +## 2 of the License, or (at your option) any later version. +## +## This file is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +## USA, or contact Ralf S. Engelschall . +## + +## +## COMMON UTILITY CODE +## + +# commonly used ASCII values +ASC_TAB=" " +ASC_NL=" +" + +# determine name of tool +if [ ".$tool" != . ]; then + # used inside shtool script + toolcmd="$0 $tool" + toolcmdhelp="shtool $tool" + msgprefix="shtool:$tool" +else + # used as standalone script + toolcmd="$0" + toolcmdhelp="sh $0" + msgprefix="$str_tool" +fi + +# parse argument specification string +eval `echo $arg_spec |\ + sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'` + +# parse option specification string +eval `echo h.$opt_spec |\ + sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'` + +# interate over argument line +opt_PREV='' +while [ $# -gt 0 ]; do + # special option stops processing + if [ ".$1" = ".--" ]; then + shift + break + fi + + # determine option and argument + opt_ARG_OK=no + if [ ".$opt_PREV" != . ]; then + # merge previous seen option with argument + opt_OPT="$opt_PREV" + opt_ARG="$1" + opt_ARG_OK=yes + opt_PREV='' + else + # split argument into option and argument + case "$1" in + -[a-zA-Z0-9]*) + eval `echo "x$1" |\ + sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \ + -e 's/";\(.*\)$/"; opt_ARG="\1"/'` + ;; + -[a-zA-Z0-9]) + opt_OPT=`echo "x$1" | cut -c3-` + opt_ARG='' + ;; + *) + break + ;; + esac + fi + + # eat up option + shift + + # determine whether option needs an argument + eval "opt_MODE=\$opt_MODE_${opt_OPT}" + if [ ".$opt_ARG" = . -a ".$opt_ARG_OK" != .yes ]; then + if [ ".$opt_MODE" = ".:" -o ".$opt_MODE" = ".+" ]; then + opt_PREV="$opt_OPT" + continue + fi + fi + + # process option + case $opt_MODE in + '.' ) + # boolean option + eval "opt_${opt_OPT}=yes" + ;; + ':' ) + # option with argument (multiple occurances override) + eval "opt_${opt_OPT}=\"\$opt_ARG\"" + ;; + '+' ) + # option with argument (multiple occurances append) + eval "opt_${opt_OPT}=\"\$opt_${opt_OPT}\${ASC_NL}\$opt_ARG\"" + ;; + * ) + echo "$msgprefix:Error: unknown option: \`-$opt_OPT'" 1>&2 + echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2 + exit 1 + ;; + esac +done +if [ ".$opt_PREV" != . ]; then + echo "$msgprefix:Error: missing argument to option \`-$opt_PREV'" 1>&2 + echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2 + exit 1 +fi + +# process help option +if [ ".$opt_h" = .yes ]; then + echo "Usage: $toolcmdhelp $str_usage" + exit 0 +fi + +# complain about incorrect number of arguments +case $arg_MODE in + '=' ) + if [ $# -ne $arg_NUMS ]; then + echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2 + echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2 + exit 1 + fi + ;; + '+' ) + if [ $# -lt $arg_NUMS ]; then + echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2 + echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2 + exit 1 + fi + ;; +esac + +# establish a temporary file on request +if [ ".$gen_tmpfile" = .yes ]; then + if [ ".$TMPDIR" != . ]; then + tmpdir="$TMPDIR" + elif [ ".$TEMPDIR" != . ]; then + tmpdir="$TEMPDIR" + else + tmpdir="/tmp" + fi + tmpfile="$tmpdir/.shtool.$$" + rm -f $tmpfile >/dev/null 2>&1 + touch $tmpfile + chmod 600 $tmpfile +fi + Index: ossp-pkg/shtool/sh.install RCS File: /v/ossp/cvs/ossp-pkg/shtool/sh.install,v rcsdiff -q -kk '-r1.21' '-r1.22' -u '/v/ossp/cvs/ossp-pkg/shtool/sh.install,v' 2>/dev/null --- sh.install 2001/06/14 14:24:16 1.21 +++ sh.install 2001/06/14 19:02:54 1.22 @@ -107,7 +107,9 @@ # adjust the target file if [ ".$opt_e" != . ]; then sed='sed' - for e in $opt_e; do + OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS" + for e + do sed="$sed -e '$e'" done cp $dsttmp $dsttmp.old Index: ossp-pkg/shtool/sh.scpp RCS File: /v/ossp/cvs/ossp-pkg/shtool/sh.scpp,v rcsdiff -q -kk '-r1.18' '-r1.19' -u '/v/ossp/cvs/ossp-pkg/shtool/sh.scpp,v' 2>/dev/null --- sh.scpp 2001/01/17 09:55:11 1.18 +++ sh.scpp 2001/06/14 19:02:54 1.19 @@ -68,10 +68,16 @@ if [ ".$opt_v" = .yes ]; then echo $src | $awk '{ printf(" %s", $0); }' 1>&2 fi - if [ ".$opt_f" = . ]; then - inputcmd="cat $src" + if [ ".$opt_f" != . ]; then + inputcmd="sed" + OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_f; IFS="$OIFS" + for e + do + inputcmd="$inputcmd -e '$e'" + done + inputcmd="$inputcmd $src" else - inputcmd="sed $opt_f $src" + inputcmd="cat $src" fi $inputcmd |\ $awk ' Index: ossp-pkg/shtool/sh.subst RCS File: /v/ossp/cvs/ossp-pkg/shtool/sh.subst,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/shtool/sh.subst,v' | diff -u /dev/null - -L'ossp-pkg/shtool/sh.subst' 2>/dev/null --- ossp-pkg/shtool/sh.subst +++ - 2024-05-12 01:43:35.343245780 +0200 @@ -0,0 +1,165 @@ +## +## subst -- Apply sed(1) substitution operations +## Copyright (c) 2001 Ralf S. Engelschall +## Originally written for OpenPKG's rpmtool +## +## 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 +## License as published by the Free Software Foundation; either version +## 2 of the License, or (at your option) any later version. +## +## This file is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +## USA, or contact Ralf S. Engelschall . +## + +str_tool="subst" +str_usage="[-v] [-t] [-n] [-s] [-i] [-b] [-e] [-f] [] [...]" +gen_tmpfile=yes +arg_spec="0+" +opt_spec="v.t.n.s.i.b:e+f:" +opt_v=no +opt_t=no +opt_n=no +opt_s=no +opt_i=no +opt_b="" +opt_e="" +opt_f="" + +. ./sh.common + +# remember optional list of file(s) +files="$*" + +# parameter consistency check +if [ $# -eq 0 -a ".$opt_b" != . ]; then + echo "$msgprefix:Error: option -b cannot be applied to stdin" 1>&2 + exit 1 +fi +if [ $# -eq 0 -a ".$opt_s" = .yes ]; then + echo "$msgprefix:Error: option -s cannot be applied to stdin" 1>&2 + exit 1 +fi + +# build underlying sed(1) command +sedcmd='sed' +if [ ".$opt_e" != . ]; then + OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS" + for e + do + sedcmd="$sedcmd -e '$e'" + done +elif [ ".$opt_f" != . ]; then + if [ ! -f $opt_f ]; then + echo "$msgprefix:Error: command file \`$opt_f' not found" 1>&2 + exit 1 + fi + sedcmd="$sedcmd -f '$opt_f'" +else + echo "$msgprefix:Error: either -e option(s) or -f option required" 1>&2 + exit 1 +fi + +# determine extension for original file +orig=".orig" +if [ ".$opt_b" != . ]; then + orig="$opt_b" +fi + +# apply sed(1) operation(s) +if [ ".$files" != . ]; then + # apply operation(s) to files + for file in $files; do + test ".$file" = . && continue + if [ ! -f $file ]; then + echo "$msgprefix:Warning: file \`$file' not found" 1>&2 + continue + fi + + # handle interactive mode + if [ ".$opt_i" = .yes ]; then + eval "$sedcmd <$file >$file.new" + skip=no + if cmp $file $file.new >/dev/null 2>&1; then + rm -f $file.new + skip=yes + else + (diff -u1 $file $file.new >$tmpfile) 2>/dev/null + if [ ".`cat $tmpfile`" = . ]; then + (diff -C1 $file $file.new >$tmpfile) 2>/dev/null + if [ ".`cat $tmpfile`" = . ]; then + echo "$msgprefix:Warning: unable to show difference for file \`$file'" 1>&2 + cp /dev/null $tmpfile + fi + fi + rm -f $file.new + cat $tmpfile + echo dummy | awk '{ printf("%s", TEXT); }' TEXT=">>> Apply [Y/n]: " + read input + if [ ".$input" != .Y ] &&\ + [ ".$input" != .y ] &&\ + [ ".$input" != . ]; then + skip=yes + fi + fi + if [ ".$skip" = .yes ]; then + if [ ".$opt_v" = .yes ]; then + echo "file \`$file' -- skipped" 1>&2 + fi + continue + fi + fi + + # apply sed(1) operation(s) + if [ ".$opt_v" = .yes ]; then + echo "patching \`$file'" 1>&2 + fi + if [ ".$opt_t" = .yes ]; then + echo "\$ cp -p $file $file$orig" + echo "\$ $sedcmd <$file$orig >$file" + fi + if [ ".$opt_n" = .no ]; then + cp -p $file $file$orig + eval "$sedcmd <$file$orig >$file" + fi + + # optionally fix timestamp + if [ ".$opt_s" = .yes ]; then + if [ ".$opt_t" = .yes ]; then + echo "\$ touch -r $file$orig $file" + fi + if [ ".$opt_n" = .no ]; then + touch -r $file$orig $file + fi + fi + + # optionally remove preserved original file + if [ ".$opt_b" = . ]; then + if [ ".$opt_t" = .yes ]; then + echo "\$ rm -f $file$orig" + fi + if [ ".$opt_n" = .no ]; then + rm -f $file$orig + fi + fi + done +else + # apply operation(s) to stdin/stdout + if [ ".$opt_v" = .yes ]; then + echo "patching " 1>&2 + fi + if [ ".$opt_t" = .yes ]; then + echo "\$ $sedcmd" + fi + if [ ".$opt_n" = .no ]; then + eval "$sedcmd" + fi +fi + Index: ossp-pkg/shtool/shtool.pod RCS File: /v/ossp/cvs/ossp-pkg/shtool/shtool.pod,v rcsdiff -q -kk '-r1.52' '-r1.53' -u '/v/ossp/cvs/ossp-pkg/shtool/shtool.pod,v' 2>/dev/null --- shtool.pod 2001/06/14 14:24:16 1.52 +++ shtool.pod 2001/06/14 19:02:54 1.53 @@ -250,6 +250,10 @@ Roll standardized distribution tarballs. +=item B + +Apply sed(1) substitution operations. + =item B Simple operating system and platform architecture guesser which @@ -555,6 +559,36 @@ shtool tarball -o foobar-$$V.tar.gz -c 'gzip -9' \ -u bar -g gnu -e 'CVS,\.cvsignore' . +=item B [B<-v>] [B<-t>] [B<-n>] [B<-s>] [B<-i>] [B<-b> I] [B<-e> I] [B<-f> I] [I] [I ...] + +This command applies one or more sed(1) substitution operations to +F or any number of files. The sed(1) operations are either +specified on the command line with option ``B<-e>'' or are contained +in a file I and are specified with option ``B<-f>''. The +original untouched I is usually overridden. If option ``B<-b>'' +is given and specifies a file extension, the original file is preserved +as ``I.I''. If option ``B<-s>'' (stealth) is specified, +the timestamp is preserved on I, too. Option ``B<-i>'' enables +interactive mode where the user has to approve each operation. Option +``B<-n>'' (no operation) can be used to disable the actual execution of +the essential shell commands which would be executed. Option ``B<-t>'' +(trace) can be used to enable the output of the essential shell commands +which are executed. Option ``B<-v>'' (verbose) can be used to display +the files which are patched. + +Example: + + # interactive shell + $ shtool subst -i -e 's;(c) \([0-9]*\)-2000;(c) \1-2001;' *.[ch] + + # RPM spec-file + %install + shtool subst -v -n \ + -e 's;^\(prefix=\).*;\1 $RPM_BUILD_ROOT%{_prefix};g' \ + -e 's;^\(sysconfdir=\).*;\1 $RPM_BUILD_ROOT%{_prefix}/etc;g' \ + `find . -name Makefile -print` + make install + =item B This command is a simple operating system and platform architecture guesser Index: ossp-pkg/shtool/shtoolize.in RCS File: /v/ossp/cvs/ossp-pkg/shtool/shtoolize.in,v rcsdiff -q -kk '-r1.23' '-r1.24' -u '/v/ossp/cvs/ossp-pkg/shtool/shtoolize.in,v' 2>/dev/null --- shtoolize.in 2001/06/14 14:24:17 1.23 +++ shtoolize.in 2001/06/14 19:02:54 1.24 @@ -35,7 +35,7 @@ # Available modules my @available = qw( echo mdate table prop move install mkdir mkln mkshadow - fixperm tarball guessos arx slo scpp version path + fixperm tarball subst guessos arx slo scpp version path ); ## Index: ossp-pkg/shtool/shtoolize.pod RCS File: /v/ossp/cvs/ossp-pkg/shtool/shtoolize.pod,v rcsdiff -q -kk '-r1.6' '-r1.7' -u '/v/ossp/cvs/ossp-pkg/shtool/shtoolize.pod,v' 2>/dev/null --- shtoolize.pod 2001/06/14 14:24:17 1.6 +++ shtoolize.pod 2001/06/14 19:02:54 1.7 @@ -54,6 +54,7 @@ mkshadow Make a shadow tree fixperm Fix file permissions inside a source tree tarball Roll distribution tarballs + subst Apply sed(1) substitution operations guessos Simple OS/platform guesser arx Extended archive command slo Separate linker options by library class