[flang][runtime] Make defined formatted I/O process format elementally (#74150)
[llvm-project.git] / libcxx / utils / zos_rename_dll_side_deck.sh
blobadab79f48bfd6bac7f9678e5d9472d58b752952e
1 #!/usr/bin/env bash
3 # Script to rename DLL name within side deck.
6 # Stops execution if a command or pipeline has an error.
7 set -e
9 sidedeck=$1
10 old_dll_name=$2
11 new_dll_name=$3
13 function error() {
14 printf "ERROR: %s\n" "$*"
15 exit 1
18 function usage() {
19 cat <<EOF
20 Usage: $(basename $0) <side deck file> <old dll name> <new dll name>:
21 [-h|--help] Display this help and exit.
22 EOF
25 rename_dll_name_inside_side_deck() {
27 if [[ -z "$sidedeck" || -z "$old_dll_name" || -z "$new_dll_name" ]]; then
28 usage
29 error "All 3 parameters must be specified."
32 [[ -f "$sidedeck" ]] || error "The '$sidedeck' file must exists."
34 old_len=${#old_dll_name}
35 new_len=${#new_dll_name}
37 if (( $new_len > $old_len )); then
38 error "New DLL name $new_dll_name must have $old_len characters or less."
41 if ((padding_len=$old_len-$new_len )); then
42 pad=$(printf "%*s" $padding_len "")
45 # Touch the temp. file and set the tag to 1047 first so the redirecting statement
46 # will write in 1047 and not 819 encoding.
47 touch $sidedeck.tmp; chtag -tc1047 $sidedeck.tmp
48 sed "/ IMPORT /s/'$old_dll_name/$pad'$new_dll_name/g" $sidedeck > $sidedeck.tmp
49 mv $sidedeck.tmp $sidedeck
52 function main() {
53 rename_dll_name_inside_side_deck
56 main "$@"