summaryrefslogtreecommitdiff
path: root/web/noweb/src/awkname
blob: 157843b903042b90c4a71c9d3ffcbe2ff7069bd8 (plain)
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
#!/bin/sh

case $# in
  1) ;;
  *) echo "Usage: `basename $0` [awk|nawk|gawk]" 1>&2; exit 1
esac

rc=0
new=$(mktemp); old=$(mktemp)

for file in lib/emptydefn lib/unmarkup lib/toascii lib/btdefn \
                        awk/noidx awk/totex awk/tohtml awk/noindex \
                        shell/noroff shell/toroff lib/pipedocs \
                        shell/nocount shell/nountangle shell/noweb shell/noroots
do
  trap 'rm -f $new $old; exit 1' 1 2 15 # clean up files
  if sed -e "s/nawk '/$1 '/" -e "s/nawk -f/$1 -f/" -e "s/AWK=nawk/AWK=$1/" <$file >$new
  then
    cp $file $old       # save original file
    trap 'trap "" 1 2 15; cp $old $file # ignore signals
          rm -f $new $old; exit 1' 1 2 15       # during restore
    cp $new $file
  else
    echo "awkname: failed to change $file" 1>&2
    rc=1
  fi
done
rm -f $new $old
exit $rc