xref: /dragonfly/tools/tools/locale/tools/finalize (revision 279dd846)
1#!/bin/sh
2#
3# This is a helper script for the Makefile in the parent directory.
4# When the localization definitions are generated in the draft area,
5# this script will copy base ones that others symlink to, and rearrange
6# the generate makefile to pull the LOCALES first.
7#
8
9usage ()
10{
11   echo "finalize <type>' to package standard localization"
12   echo "type must be one of { monetdef, msgdef, numericdef, timedef, colldef, ctypedef }"
13   exit 1
14}
15
16[ $# -ne 1 ] && usage
17[ $1 = "monetdef" -o $1 = "msgdef" -o $1 = "colldef" -o \
18  $1 = "numericdef" -o $1 = "timedef" -o $1 = "ctypedef" ] || usage
19
20self=$(realpath $0)
21base=$(dirname ${self})
22old=${base}/../${1}.draft
23new=${base}/../${1}
24TEMP=/tmp/${1}.locales
25TEMP2=/tmp/${1}.hashes
26FULLMAP=/tmp/utf8-map
27FULLEXTRACT=/tmp/extracted-names
28AWKCMD="/## PLACEHOLDER/ { \
29	  while ( getline line < \"${TEMP}\" ) {print line} } \
30	!/## PLACEHOLDER/ { print \$0 }"
31
32grep '^LOCALES+' ${old}/Makefile > ${TEMP}
33
34if [ $1 = "ctypedef" ]
35then
36keep=$(cat ${TEMP} | awk '{ print $2 ".src" }')
37(cd ${old} && md5 -r ${keep} | sort) > ${TEMP2}
38keep=$(awk '{ if ($1 != last1) print $2; last1 = $1; }' ${TEMP2})
39for original in ${keep}
40do
41	cp ${old}/${original} ${new}/
42done
43linx=$(awk '{ if ($1 == last1) { print "ln -s " last2 " ${new}/" $2 ";"} \
44else {last1 = $1; last2 = $2}}' ${TEMP2})
45eval $linx
46rm -f ${TEMP2}
47	/usr/bin/sed -E -e 's/[ ]+/ /g' \
48		${CLDRDIR}/posix/UTF-8.cm \
49		> ${base}/../etc/final-maps/map.UTF-8
50CHARMAPS="ARMSCII-8 Big5 Big5HKSCS CP1131 CP1251 \
51	CP866 GB2312 GBK ISCII-DEV ISO8859-1 \
52	ISO8859-13 ISO8859-15 ISO8859-2 ISO8859-4 \
53	ISO8859-5 ISO8859-7 ISO8859-9 KOI8-R KOI8-U \
54	PT154 SJIS US-ASCII eucCN eucJP eucKR"
55
56# GB18030 blows up, use pre-generate Illumos version
57
58for map in ${CHARMAPS}
59do
60encoding=${map}
61if [ ${map} = "Big5HKSCS" ]
62then
63encoding="Big5"
64fi
65/usr/local/bin/perl ${base}/convert_map.pl \
66	${base}/../etc/charmaps/${map}.TXT ${encoding} \
67	| /usr/bin/sed -E -e 's/	+/ /g' \
68	> ${base}/../etc/final-maps/map.${map}
69	echo map ${map} converted.
70done
71
72else  # below is everything but ctypedef
73
74keep=$(cat ${TEMP} | awk '{ print $2 }')
75for original in ${keep}
76do
77	cp ${old}/${original}.src ${new}/
78done
79
80fi
81
82grep -v '^LOCALES+' ${old}/Makefile | awk "${AWKCMD}" > ${new}/Makefile
83
84rm -f ${TEMP}
85