11cb0ef41Sopenharmony_ci#!/bin/sh
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciif [ "$#" -ne 3 ] || ! [ -f "$1" ]; then
41cb0ef41Sopenharmony_ci  echo ===========================
51cb0ef41Sopenharmony_ci  echo "Script to modify sidedeck references to a new DLL name"
61cb0ef41Sopenharmony_ci  echo ===========================
71cb0ef41Sopenharmony_ci  echo "Usage: $0 originalsidedeck modifiedsidedeck newdllreference" >&2
81cb0ef41Sopenharmony_ci  exit 1
91cb0ef41Sopenharmony_cifi
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cioriginalsidedeck=$1
121cb0ef41Sopenharmony_cioutputsidedeck=$2
131cb0ef41Sopenharmony_cinewdllname=$3
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciSCRIPT_DIR=$(dirname "$0")
161cb0ef41Sopenharmony_ciID=`date +%C%y%m%d_%H%M%S`
171cb0ef41Sopenharmony_ciTMP="/tmp/sidedeck-$(basename "$0").$ID.tmp"
181cb0ef41Sopenharmony_ciTMP2="/tmp/sidedeck-$(basename "$0").$ID.tmp.2"
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci# Remove on exit/interrupt
211cb0ef41Sopenharmony_citrap '/bin/rm -rf "$TMP" "$TMP2" && exit' EXIT INT TERM QUIT HUP
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ciset -x
241cb0ef41Sopenharmony_cidd conv=unblock cbs=80 if="$originalsidedeck" of="$TMP"
251cb0ef41Sopenharmony_cichtag -tc 1047 "$TMP"
261cb0ef41Sopenharmony_ci"$SCRIPT_DIR"/sdwrap.py -u -i "$TMP" -o "$TMP2"
271cb0ef41Sopenharmony_cichtag -tc 819 "$TMP2"
281cb0ef41Sopenharmony_cised -e "s/\(^ IMPORT \(DATA\|CODE\)64,\)'[^']*'/\1'$newdllname'/g" "$TMP2" > "$TMP"
291cb0ef41Sopenharmony_ci"$SCRIPT_DIR"/sdwrap.py -i "$TMP" -o "$TMP2"
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci# Reformat sidedeck to be USS compatible
321cb0ef41Sopenharmony_ciiconv -f ISO8859-1 -t IBM-1047 "$TMP2" > "$TMP"
331cb0ef41Sopenharmony_cidd conv=block cbs=80 if="$TMP" of="$outputsidedeck"
34