brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · adab79f Raw
58 lines · bash
1#!/usr/bin/env bash2#3# Script to rename DLL name within side deck.4#5 6# Stops execution if a command or pipeline has an error.7set -e8 9sidedeck=$110old_dll_name=$211new_dll_name=$312 13function error() {14  printf "ERROR: %s\n" "$*"15  exit 116}17 18function usage() {19cat <<EOF20Usage: $(basename $0) <side deck file> <old dll name> <new dll name>:21          [-h|--help] Display this help and exit.22EOF23}24 25rename_dll_name_inside_side_deck() {26 27if [[ -z "$sidedeck" || -z "$old_dll_name" || -z "$new_dll_name" ]]; then28  usage29  error "All 3 parameters must be specified."30fi31 32[[ -f "$sidedeck" ]] || error "The '$sidedeck' file must exists."33 34old_len=${#old_dll_name}35new_len=${#new_dll_name}36 37if (( $new_len > $old_len )); then38  error "New DLL name $new_dll_name must have $old_len characters or less."39fi40 41if ((padding_len=$old_len-$new_len )); then42  pad=$(printf "%*s" $padding_len "")43fi44 45# Touch the temp. file and set the tag to 1047 first so the redirecting statement46# will write in 1047 and not 819 encoding.47touch $sidedeck.tmp; chtag -tc1047 $sidedeck.tmp48sed "/ IMPORT /s/'$old_dll_name/$pad'$new_dll_name/g" $sidedeck > $sidedeck.tmp49mv $sidedeck.tmp $sidedeck50}51 52function main() {53  rename_dll_name_inside_side_deck54}55 56main "$@"57 58