home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
300-399
/
ff319.lzh
/
CNewsSrc
/
cnews.orig.lzh
/
conf
/
subst
< prev
next >
Wrap
Text File
|
1989-06-27
|
1KB
|
84 lines
#! /bin/sh
# subst - substitute strings into files, carefully
PATH=/bin:/usr/bin ; export PATH
case "$1"
in
-f)
substs=$2
shift ; shift
;;
*)
echo "$0: no substitutions file given" >&2
exit 2
;;
esac
them="`sed '/^#/d; s/^\\([^ ]*\\) *\\([^ ]*\\)$/s#@<\\1>@#\\2#g/' $substs`"
for f
do
# first, figure out temporary names
case "$f"
in
*/*)
file="`expr \"$f\" : '.*/\\([^/]*\\)'`"
dir="`expr \"$f\" : '\\(.*\\)/[^/]*'`"
new="$dir/n.$file"
old="$dir/o.$file"
;;
*)
new="n.$f"
old="o.$f"
;;
esac
echo "$f:"
# test existences
if test ! -f $f
then
echo "$0: cannot find \`$f'" >&2
continue # NOTE CONTINUE
fi
if test -r $new
then
echo "$0: $new exists, cannot proceed" >&2
exit 1
fi
if test -r $old
then
echo "$0: $old exists, cannot proceed" >&2
exit 1
fi
( >$old >$new ) 2>/dev/null
if test ! -w "$old" -o ! -w "$new"
then
rm -f $old $new
echo "$0: cannot create temporaries $old $new" >&2
exit 1
fi
# generate the new version
trap "rm -f $new; exit" 1 2 15
sed "/=()<.*>()=/{
h
n
g
s/.*=()<//
s/>()=.*//
$them
}" $f >$new
# substitute new for old
trap "mv $old $f; exit" 1 2 15
mv $f $old
mv $new $f
# dispense with the old version
trap "rm -f $old; exit" 1 2 15
rm $old
done