xref: /aosp_15_r20/external/icu/icu4c/as_is/os390/unpax-icu.sh (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker#!/bin/sh
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) 2001-2010, 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# Steven R. Loomis
10*0e209d39SAndroid Build Coastguard Worker# George Rhoten
11*0e209d39SAndroid Build Coastguard Worker#
12*0e209d39SAndroid Build Coastguard Worker# Shell script to unpax ICU and convert the files to an EBCDIC codepage.
13*0e209d39SAndroid Build Coastguard Worker# After extracting to EBCDIC, binary files are re-extracted without the
14*0e209d39SAndroid Build Coastguard Worker# EBCDIC conversion, thus restoring them to original codepage.
15*0e209d39SAndroid Build Coastguard Worker#
16*0e209d39SAndroid Build Coastguard Worker# Set the following variable to the list of binary file suffixes (extensions)
17*0e209d39SAndroid Build Coastguard Worker
18*0e209d39SAndroid Build Coastguard Worker#ICU specific binary files
19*0e209d39SAndroid Build Coastguard Worker#****************************************************************************
20*0e209d39SAndroid Build Coastguard Workerbinary_suffixes='brk BRK bin BIN res RES cnv CNV dat DAT icu ICU spp SPP xml XML nrm NRM utf16be UTF16BE'
21*0e209d39SAndroid Build Coastguard Workerdata_files='icu/source/data/brkitr/* icu/source/data/locales/* icu/source/data/coll/* icu/source/data/rbnf/* icu/source/data/mappings/* icu/source/data/misc/* icu/source/data/translit/* icu/source/data/unidata/* icu/source/test/testdata/*'
22*0e209d39SAndroid Build Coastguard Worker
23*0e209d39SAndroid Build Coastguard Worker#****************************************************************************
24*0e209d39SAndroid Build Coastguard Worker# Function:     usage
25*0e209d39SAndroid Build Coastguard Worker# Description:  Prints out text that describes how to call this script
26*0e209d39SAndroid Build Coastguard Worker# Input:        None
27*0e209d39SAndroid Build Coastguard Worker# Output:       None
28*0e209d39SAndroid Build Coastguard Worker#****************************************************************************
29*0e209d39SAndroid Build Coastguard Workerusage()
30*0e209d39SAndroid Build Coastguard Worker{
31*0e209d39SAndroid Build Coastguard Worker    echo "Enter archive filename as a parameter: $0 icu-archive.tar"
32*0e209d39SAndroid Build Coastguard Worker}
33*0e209d39SAndroid Build Coastguard Worker
34*0e209d39SAndroid Build Coastguard Worker#****************************************************************************
35*0e209d39SAndroid Build Coastguard Worker# first make sure we at least one arg and it's a file we can read
36*0e209d39SAndroid Build Coastguard Worker#****************************************************************************
37*0e209d39SAndroid Build Coastguard Worker
38*0e209d39SAndroid Build Coastguard Worker# check for no arguments
39*0e209d39SAndroid Build Coastguard Workerif [ $# -eq 0 ]; then
40*0e209d39SAndroid Build Coastguard Worker    usage
41*0e209d39SAndroid Build Coastguard Worker    exit
42*0e209d39SAndroid Build Coastguard Workerfi
43*0e209d39SAndroid Build Coastguard Workertar_file=$1
44*0e209d39SAndroid Build Coastguard Workerif [ ! -r $tar_file ]; then
45*0e209d39SAndroid Build Coastguard Worker    echo "$tar_file does not exist or cannot be read."
46*0e209d39SAndroid Build Coastguard Worker    usage
47*0e209d39SAndroid Build Coastguard Worker    exit
48*0e209d39SAndroid Build Coastguard Workerfi
49*0e209d39SAndroid Build Coastguard Worker
50*0e209d39SAndroid Build Coastguard Workerecho ""
51*0e209d39SAndroid Build Coastguard Workerecho "Extracting from $tar_file ..."
52*0e209d39SAndroid Build Coastguard Workerecho ""
53*0e209d39SAndroid Build Coastguard Worker# extract files while converting them to EBCDIC
54*0e209d39SAndroid Build Coastguard Workerpax -rvf $tar_file -o to=IBM-1047,from=ISO8859-1 -o setfiletag
55*0e209d39SAndroid Build Coastguard Worker
56*0e209d39SAndroid Build Coastguard Worker#****************************************************************************
57*0e209d39SAndroid Build Coastguard Worker# For files we have restored as CCSID 37, check the BOM to see if they
58*0e209d39SAndroid Build Coastguard Worker# should be processed as 819.  Also handle files with special paths. Files
59*0e209d39SAndroid Build Coastguard Worker# that match will be added to binary files lists.  The lists will in turn
60*0e209d39SAndroid Build Coastguard Worker# be processed to restore files as 819.
61*0e209d39SAndroid Build Coastguard Worker#****************************************************************************
62*0e209d39SAndroid Build Coastguard Workerecho ""
63*0e209d39SAndroid Build Coastguard Workerecho "Determining binary files by BOM ..."
64*0e209d39SAndroid Build Coastguard Workerecho ""
65*0e209d39SAndroid Build Coastguard Worker
66*0e209d39SAndroid Build Coastguard Worker# When building in ASCII mode, text files are converted as ASCII
67*0e209d39SAndroid Build Coastguard Workerif [ "${ICU_ENABLE_ASCII_STRINGS}" -eq 1 ]; then
68*0e209d39SAndroid Build Coastguard Worker    binary_suffixes="$binary_suffixes txt TXT ucm UCM"
69*0e209d39SAndroid Build Coastguard Workerelif [ -f icu/as_is/bomlist.txt ];
70*0e209d39SAndroid Build Coastguard Workerthen
71*0e209d39SAndroid Build Coastguard Worker    echo 'Using icu/as_is/bomlist.txt'
72*0e209d39SAndroid Build Coastguard Worker    binary_files=$(cat icu/as_is/bomlist.txt)
73*0e209d39SAndroid Build Coastguard Workerelse
74*0e209d39SAndroid Build Coastguard Worker    echo "Analyzing files .."
75*0e209d39SAndroid Build Coastguard Worker	for file in `find ./icu \( -name \*.txt -print \) | sed -e 's/^\.\///'`; do
76*0e209d39SAndroid Build Coastguard Worker		bom8=`head -c 3 $file|\
77*0e209d39SAndroid Build Coastguard Worker			od -t x1|\
78*0e209d39SAndroid Build Coastguard Worker			head -n 1|\
79*0e209d39SAndroid Build Coastguard Worker			sed 's/  */ /g'|\
80*0e209d39SAndroid Build Coastguard Worker			cut -f2-4 -d ' '|\
81*0e209d39SAndroid Build Coastguard Worker			tr 'A-Z' 'a-z'`;
82*0e209d39SAndroid Build Coastguard Worker		#Find a converted UTF-8 BOM
83*0e209d39SAndroid Build Coastguard Worker		if [ "$bom8" = "57 8b ab" ]
84*0e209d39SAndroid Build Coastguard Worker		then
85*0e209d39SAndroid Build Coastguard Worker			binary_files="$binary_files $file";
86*0e209d39SAndroid Build Coastguard Worker		fi
87*0e209d39SAndroid Build Coastguard Worker	done
88*0e209d39SAndroid Build Coastguard Workerfi
89*0e209d39SAndroid Build Coastguard Worker
90*0e209d39SAndroid Build Coastguard Workerecho "Looking for binary suffixes.."
91*0e209d39SAndroid Build Coastguard Worker
92*0e209d39SAndroid Build Coastguard Workerfor i in $(pax -f $tar_file 2>/dev/null)
93*0e209d39SAndroid Build Coastguard Workerdo
94*0e209d39SAndroid Build Coastguard Worker	case $i in
95*0e209d39SAndroid Build Coastguard Worker	*/) ;;		# then this entry is a directory
96*0e209d39SAndroid Build Coastguard Worker	*.*)		# then this entry has a dot in the filename
97*0e209d39SAndroid Build Coastguard Worker		for j in $binary_suffixes
98*0e209d39SAndroid Build Coastguard Worker		do
99*0e209d39SAndroid Build Coastguard Worker			# We substitute the suffix more than once
100*0e209d39SAndroid Build Coastguard Worker			# to handle files like NormalizationTest-3.2.0.txt
101*0e209d39SAndroid Build Coastguard Worker			suf=${i#*.*}
102*0e209d39SAndroid Build Coastguard Worker			suf=${suf#*.*}
103*0e209d39SAndroid Build Coastguard Worker			suf=${suf#*.*}
104*0e209d39SAndroid Build Coastguard Worker			if [ "$suf" = "$j" ]
105*0e209d39SAndroid Build Coastguard Worker			then
106*0e209d39SAndroid Build Coastguard Worker				binary_files="$binary_files $i"
107*0e209d39SAndroid Build Coastguard Worker				break
108*0e209d39SAndroid Build Coastguard Worker			fi
109*0e209d39SAndroid Build Coastguard Worker		done
110*0e209d39SAndroid Build Coastguard Worker		;;
111*0e209d39SAndroid Build Coastguard Worker	*) ;;		# then this entry does not have a dot in it
112*0e209d39SAndroid Build Coastguard Worker    esac
113*0e209d39SAndroid Build Coastguard Workerdone
114*0e209d39SAndroid Build Coastguard Worker
115*0e209d39SAndroid Build Coastguard Worker# now see if a re-extract of binary files is necessary
116*0e209d39SAndroid Build Coastguard Workerif [ ${#binary_files} -eq 0 ]; then
117*0e209d39SAndroid Build Coastguard Worker    echo ""
118*0e209d39SAndroid Build Coastguard Worker    echo "There are no binary files to restore."
119*0e209d39SAndroid Build Coastguard Workerelse
120*0e209d39SAndroid Build Coastguard Worker    echo "Restoring binary files ..."
121*0e209d39SAndroid Build Coastguard Worker    echo ""
122*0e209d39SAndroid Build Coastguard Worker    rm $binary_files
123*0e209d39SAndroid Build Coastguard Worker    pax -rvf $tar_file $binary_files
124*0e209d39SAndroid Build Coastguard Worker    # Tag the files as binary for proper interaction with the _BPXK_AUTOCVT
125*0e209d39SAndroid Build Coastguard Worker    # environment setting
126*0e209d39SAndroid Build Coastguard Worker    chtag -b $binary_files
127*0e209d39SAndroid Build Coastguard Workerfi
128*0e209d39SAndroid Build Coastguard Workerecho ""
129*0e209d39SAndroid Build Coastguard Workerecho "$0 has completed extracting ICU from $tar_file."
130