xref: /aosp_15_r20/external/icu/icu4c/as_is/os400/fixup-icu.sh (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker#!/usr/bin/qsh
2*0e209d39SAndroid Build Coastguard Worker# Copyright (C) 2016 and later: Unicode, Inc. and others.
3*0e209d39SAndroid Build Coastguard Worker# License & terms of use: http://www.unicode.org/copyright.html
4*0e209d39SAndroid Build Coastguard Worker#   Copyright (C) 2000-2011, International Business Machines
5*0e209d39SAndroid Build Coastguard Worker#   Corporation and others.  All Rights Reserved.
6*0e209d39SAndroid Build Coastguard Worker#
7*0e209d39SAndroid Build Coastguard Worker# Authors:
8*0e209d39SAndroid Build Coastguard Worker# Ami Fixler
9*0e209d39SAndroid Build Coastguard Worker# Barry Novinger
10*0e209d39SAndroid Build Coastguard Worker# Steven R. Loomis
11*0e209d39SAndroid Build Coastguard Worker# George Rhoten
12*0e209d39SAndroid Build Coastguard Worker# Jason Spieth
13*0e209d39SAndroid Build Coastguard Worker#
14*0e209d39SAndroid Build Coastguard Worker#
15*0e209d39SAndroid Build Coastguard Worker# This script detects if any UTF-8 files were incorrectly converted to EBCDIC, and
16*0e209d39SAndroid Build Coastguard Worker# converts them back.
17*0e209d39SAndroid Build Coastguard Worker
18*0e209d39SAndroid Build Coastguard Workerif [ -z "$QSH_VERSION" ];
19*0e209d39SAndroid Build Coastguard Workerthen
20*0e209d39SAndroid Build Coastguard Worker	QSH=0
21*0e209d39SAndroid Build Coastguard Worker    echo "QSH not detected (QSH_VERSION not set) - just testing."
22*0e209d39SAndroid Build Coastguard Workerelse
23*0e209d39SAndroid Build Coastguard Worker	QSH=1
24*0e209d39SAndroid Build Coastguard Worker	#echo "QSH version $QSH_VERSION"
25*0e209d39SAndroid Build Coastguard Workerfi
26*0e209d39SAndroid Build Coastguard Workerexport QSH
27*0e209d39SAndroid Build Coastguard Worker
28*0e209d39SAndroid Build Coastguard Workertar_file=$1
29*0e209d39SAndroid Build Coastguard Workerecho ""
30*0e209d39SAndroid Build Coastguard Workerecho "Determining binary files by BOM ..."
31*0e209d39SAndroid Build Coastguard Workerecho ""
32*0e209d39SAndroid Build Coastguard Workerbin_count=0
33*0e209d39SAndroid Build Coastguard Workerbinary_files=""
34*0e209d39SAndroid Build Coastguard Worker# Process BOMs
35*0e209d39SAndroid Build Coastguard Worker   for file in `find ./icu/source/data/unidata \( -name \*.txt -print \)`; do
36*0e209d39SAndroid Build Coastguard Worker    bom8=`od -t x1 -N 3 $file|\
37*0e209d39SAndroid Build Coastguard Worker          head -n 1|\
38*0e209d39SAndroid Build Coastguard Worker          cut -c10-18`;
39*0e209d39SAndroid Build Coastguard Worker    #Find a converted UTF-8 BOM
40*0e209d39SAndroid Build Coastguard Worker    echo "file $file bom /${bom8}/"
41*0e209d39SAndroid Build Coastguard Worker    if [ "$bom8" = "57 8b ab" ]
42*0e209d39SAndroid Build Coastguard Worker    then
43*0e209d39SAndroid Build Coastguard Worker        file="`echo $file | cut -d / -f2-`"
44*0e209d39SAndroid Build Coastguard Worker        echo "converting ${file}"
45*0e209d39SAndroid Build Coastguard Worker        if [ `echo $binary_files | wc -w` -lt 200 ]
46*0e209d39SAndroid Build Coastguard Worker        then
47*0e209d39SAndroid Build Coastguard Worker            bin_count=`expr $bin_count + 1`
48*0e209d39SAndroid Build Coastguard Worker            binary_files="$binary_files $file";
49*0e209d39SAndroid Build Coastguard Worker        else
50*0e209d39SAndroid Build Coastguard Worker            echo "Restoring binary files by BOM ($bin_count)..."
51*0e209d39SAndroid Build Coastguard Worker            rm $binary_files;
52*0e209d39SAndroid Build Coastguard Worker            pax -C 819 -rvf $tar_file $binary_files;
53*0e209d39SAndroid Build Coastguard Worker            echo "Determining binary files by BOM ($bin_count)..."
54*0e209d39SAndroid Build Coastguard Worker            binary_files="$file";
55*0e209d39SAndroid Build Coastguard Worker            bin_count=`expr $bin_count + 1`
56*0e209d39SAndroid Build Coastguard Worker        fi
57*0e209d39SAndroid Build Coastguard Worker    fi
58*0e209d39SAndroid Build Coastguard Worker  done
59*0e209d39SAndroid Build Coastguard Worker    if [ `echo $binary_files | wc -w` -gt 0 ]
60*0e209d39SAndroid Build Coastguard Worker      then
61*0e209d39SAndroid Build Coastguard Worker        echo restoring
62*0e209d39SAndroid Build Coastguard Worker        rm $binary_files
63*0e209d39SAndroid Build Coastguard Worker               pax -C 819 -rvf $tar_file $binary_files
64*0e209d39SAndroid Build Coastguard Worker       fi
65*0e209d39SAndroid Build Coastguard Worker
66*0e209d39SAndroid Build Coastguard Worker
67*0e209d39SAndroid Build Coastguard Worker
68