summaryrefslogtreecommitdiff
path: root/libcxx/utils/zos_rename_dll_side_deck.sh
blob: adab79f48bfd6bac7f9678e5d9472d58b752952e (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
#
# Script to rename DLL name within side deck.
#

# Stops execution if a command or pipeline has an error.
set -e

sidedeck=$1
old_dll_name=$2
new_dll_name=$3

function error() {
  printf "ERROR: %s\n" "$*"
  exit 1
}

function usage() {
cat <<EOF
Usage: $(basename $0) <side deck file> <old dll name> <new dll name>:
          [-h|--help] Display this help and exit.
EOF
}

rename_dll_name_inside_side_deck() {

if [[ -z "$sidedeck" || -z "$old_dll_name" || -z "$new_dll_name" ]]; then
  usage
  error "All 3 parameters must be specified."
fi

[[ -f "$sidedeck" ]] || error "The '$sidedeck' file must exists."

old_len=${#old_dll_name}
new_len=${#new_dll_name}

if (( $new_len > $old_len )); then
  error "New DLL name $new_dll_name must have $old_len characters or less."
fi

if ((padding_len=$old_len-$new_len )); then
  pad=$(printf "%*s" $padding_len "")
fi

# Touch the temp. file and set the tag to 1047 first so the redirecting statement
# will write in 1047 and not 819 encoding.
touch $sidedeck.tmp; chtag -tc1047 $sidedeck.tmp
sed "/ IMPORT /s/'$old_dll_name/$pad'$new_dll_name/g" $sidedeck > $sidedeck.tmp
mv $sidedeck.tmp $sidedeck
}

function main() {
  rename_dll_name_inside_side_deck
}

main "$@"