]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/locale/tools/finalize
Import libucl snapshot 20160604
[FreeBSD/FreeBSD.git] / tools / tools / locale / tools / finalize
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5 # This is a helper script for the Makefile in the parent directory.
6 # When the localization definitions are generated in the draft area,
7 # this script will copy base ones that others symlink to, and rearrange
8 # the generate makefile to pull the LOCALES first.
9 #
10
11 usage ()
12 {
13         echo "finalize <type>' to package standard localization"
14         echo "type must be one of { monetdef, msgdef, numericdef, timedef, colldef, ctypedef }"
15         exit 1
16 }
17
18 [ $# -ne 1 ] && usage
19 [ $1 = "monetdef" -o $1 = "msgdef" -o $1 = "colldef" -o \
20   $1 = "numericdef" -o $1 = "timedef" -o $1 = "ctypedef" ] || usage
21
22 self=$(realpath $0)
23 base=$(dirname ${self})
24 old=${base}/../${1}.draft
25 new=${base}/../${1}
26 TEMP=/tmp/${1}.locales
27 TEMP2=/tmp/${1}.hashes
28 TEMP3=/tmp/${1}.symlinks
29 TEMP4=/tmp/${1}.mapped
30 FULLMAP=/tmp/utf8-map
31 FULLEXTRACT=/tmp/extracted-names
32 AWKCMD="/## PLACEHOLDER/ { \
33           while ( getline line < \"${TEMP}\" ) {print line} } \
34         /## SYMPAIRS/ { \
35           while ( getline line < \"${TEMP3}\" ) {print line} } \
36         /## LOCALES_MAPPED/ { \
37           while ( getline line < \"${TEMP4}\" ) {print line} } \
38         !/## / { print \$0 }"
39
40 grep '^LOCALES+' ${old}/Makefile > ${TEMP}
41
42 if [ $1 = "ctypedef" ]
43 then
44         keep=$(cat ${TEMP} | awk '{ print $2 ".src" }')
45         (cd ${old} && md5 -r ${keep} | sort) > ${TEMP2}
46         keep=$(awk '{ if ($1 != last1) print $2; last1 = $1; }' ${TEMP2})
47         for original in ${keep}
48         do
49                 cp ${old}/${original} ${new}/
50         done
51         awk '{ if ($1 == last1) { print "SYMPAIRS+=\t" last2 " " $2 } \
52         else {last1 = $1; last2 = $2}}' ${TEMP2} > ${TEMP3}
53         rm -f ${TEMP2}
54         /usr/bin/sed -E -e 's/[ ]+/ /g' \
55                 ${CLDRDIR}/posix/UTF-8.cm \
56                 > ${base}/../etc/final-maps/map.UTF-8
57         /usr/bin/sed -E -e 's/[ ]+/ /g' \
58                 ${CLDRDIR}/posix/eucCN.cm \
59                 > ${base}/../etc/final-maps/map.eucCN
60         /usr/bin/sed -E -e 's/[ ]+/ /g' \
61                 ${CLDRDIR}/posix/eucCN.cm \
62                 > ${base}/../etc/final-maps/map.GB2312
63         CHARMAPS="ARMSCII-8 Big5 CP1131 CP1251 \
64                 CP866 GBK ISCII-DEV ISO8859-1 \
65                 ISO8859-13 ISO8859-15 ISO8859-2 ISO8859-4 \
66                 ISO8859-5 ISO8859-7 ISO8859-9 KOI8-R KOI8-U \
67                 PT154 SJIS US-ASCII eucJP eucKR"
68
69         # GB18030 blows up, use pre-generate Illumos version
70
71         for map in ${CHARMAPS}
72         do
73                 encoding=${map}
74                 /usr/local/bin/perl ${base}/convert_map.pl \
75                         ${base}/../etc/charmaps/${map}.TXT ${encoding} \
76                         | /usr/bin/sed -E -e 's/        +/ /g' \
77                 > ${base}/../etc/final-maps/map.${map}
78                 echo map ${map} converted.
79         done
80
81 elif [ $1 = "colldef" ]
82 then
83         awk -v tmp4=${TEMP4} '$1 == "SAME+=" && $0 !~ /legacy/ {
84                 orig=$2
85                 dest=$3
86                 gsub(/.*\./, "", orig)
87                 gsub(/.*\./, "", dest)
88                 if (orig != dest )
89                         print "LOCALES_MAPPED+=\t"$2 " "$3 > tmp4
90                 }' ${old}/Makefile
91
92         for line in $(awk '{ print $3 }' ${TEMP4}); do
93                 sed -i '' "/^SAME.*$line$/d" ${old}/Makefile
94         done
95         echo "" >> ${TEMP4}
96         for enc in ${COLLATIONS_SPECIAL}; do
97                 sed -i '' "/^.*${enc}$/d" ${TEMP4}
98                 echo "LOCALES+= ${enc}" >> ${TEMP4}
99         done
100
101         keep=$(cat ${TEMP} | awk '{ print $2 }')
102         for original in ${keep}
103         do
104                 cp ${old}/${original}.src ${new}/
105         done
106 else  # below is everything but ctypedef
107
108         keep=$(cat ${TEMP} | awk '{ print $2 }')
109         for original in ${keep}
110         do
111                 cp ${old}/${original}.src ${new}/
112         done
113
114 fi
115
116 grep -v '^LOCALES+' ${old}/Makefile | awk "${AWKCMD}" > ${new}/Makefile
117
118 rm -f ${TEMP} ${TEMP3} ${TEMP4}