]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/locale/tools/finalize
Upgrade to Unbound 1.5.9.
[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 set -e
12
13 usage ()
14 {
15         echo "finalize <type>' to package standard localization"
16         echo "type must be one of { monetdef, msgdef, numericdef, timedef, colldef, ctypedef }"
17         exit 1
18 }
19
20 [ $# -ne 1 ] && usage
21 [ $1 = "monetdef" -o $1 = "msgdef" -o $1 = "colldef" -o \
22   $1 = "numericdef" -o $1 = "timedef" -o $1 = "ctypedef" ] || usage
23
24 self=$(realpath $0)
25 base=$(dirname ${self})
26 old=${base}/../${1}.draft
27 new=${base}/../${1}
28 TEMP=/tmp/${1}.locales
29 TEMP2=/tmp/${1}.hashes
30 TEMP3=/tmp/${1}.symlinks
31 TEMP4=/tmp/${1}.mapped
32 FULLMAP=/tmp/utf8-map
33 FULLEXTRACT=/tmp/extracted-names
34 AWKCMD="/## PLACEHOLDER/ { \
35           while ( getline line < \"${TEMP}\" ) {print line} } \
36         /## SYMPAIRS/ { \
37           while ( getline line < \"${TEMP3}\" ) {print line} } \
38         /## LOCALES_MAPPED/ { \
39           while ( getline line < \"${TEMP4}\" ) {print line} } \
40         !/## / { print \$0 }"
41
42 # Rename the sources with 3 components name into the POSIX version of the name using @modifier
43 cd $old
44 for i in *_*_*.*.src; do
45         oldname=${i%.*}
46         nname=`echo $oldname | awk '{ split($0, a, "_"); print a[1]"_"a[3]"@"a[2];} '`
47         mv -i ${oldname}.src ${nname}.src
48 done
49         sed -i '' -Ee "s/([a-zA-Z]{2})_([a-zA-Z]+)_([a-zA-Z]{2}).([a-zA-Z0-9-]+)/\1_\3.\4@\2/g" ${old}/Makefile
50
51 # For variable without @modifier ambiguity do not keep the @modifier
52 for i in *@*.src; do
53         oldname=${i%.*}
54         shortname=${oldname%@*}
55         if [ $(ls ${shortname}@* | wc -l) -eq 1 -a ! -f ${shortname}.src ] ; then
56                 mv -i $i ${shortname}.src
57                 sed -i '' -e "s/${oldname}/${shortname}/g" ${old}/Makefile
58         fi
59 done
60
61 # Rename the modifiers into non abbreviated version
62 for i in *@Latn.src; do
63         if [ "$i" = "*@Latn.src" ]; then
64                 break
65         fi
66         mv ${i} ${i%@*}@latin.src
67 done
68         sed -i '' -e "s/@Latn/@latin/g" ${old}/Makefile
69 for i in *@Cyrl.src; do
70         if [ "$i" = "*@Cyrl.src" ]; then
71                 break
72         fi
73         mv ${i} ${i%@*}@cyrillic.src
74 done
75         sed -i '' -e "s/@Cyrl/@cyrillic/g" ${old}/Makefile
76
77 # On locales with multiple modifiers rename the "default" version without the @modifier
78 default_locales="sr_RS@cyrillic"
79 for i in ${default_locales}; do
80         localename=${i%@*}
81         mod=${i#*@}
82         for l in ${localename}.*@${mod}.src; do
83                 if [ "$l" = "${localename}.*@${mod}.src" ]; then
84                         break
85                 fi
86                 mv ${l} ${l%@*}.src
87                 sed -i '' -e "s/${l%.*}/${l%@*}/g" ${old}/Makefile
88         done
89 done
90 cd -
91
92 grep '^LOCALES+' ${old}/Makefile > ${TEMP}
93
94 if [ $1 = "ctypedef" ]
95 then
96         keep=$(cat ${TEMP} | awk '{ print $2 ".src" }')
97         (cd ${old} && md5 -r ${keep} | sort) > ${TEMP2}
98         keep=$(awk '{ if ($1 != last1) print $2; last1 = $1; }' ${TEMP2})
99         for original in ${keep}
100         do
101                 cp ${old}/${original} ${new}/
102         done
103         awk '{ if ($1 == last1) { print "SYMPAIRS+=\t" last2 " " $2 } \
104         else {last1 = $1; last2 = $2}}' ${TEMP2} > ${TEMP3}
105         rm -f ${TEMP2}
106         /usr/bin/sed -E -e 's/[ ]+/ /g' \
107                 ${CLDRDIR}/posix/UTF-8.cm \
108                 > ${base}/../etc/final-maps/map.UTF-8
109         /usr/bin/sed -E -e 's/[ ]+/ /g' \
110                 ${CLDRDIR}/posix/eucCN.cm \
111                 > ${base}/../etc/final-maps/map.eucCN
112         /usr/bin/sed -E -e 's/[ ]+/ /g' \
113                 ${CLDRDIR}/posix/eucCN.cm \
114                 > ${base}/../etc/final-maps/map.GB2312
115         CHARMAPS="ARMSCII-8 Big5 CP1131 CP1251 \
116                 CP866 GBK ISCII-DEV ISO8859-1 \
117                 ISO8859-13 ISO8859-15 ISO8859-2 ISO8859-4 \
118                 ISO8859-5 ISO8859-7 ISO8859-9 KOI8-R KOI8-U \
119                 PT154 SJIS US-ASCII eucJP eucKR"
120
121         # GB18030 blows up, use pre-generate Illumos version
122
123         for map in ${CHARMAPS}
124         do
125                 encoding=${map}
126                 /usr/local/bin/perl ${base}/convert_map.pl \
127                         ${base}/../etc/charmaps/${map}.TXT ${encoding} \
128                         | /usr/bin/sed -E -e 's/        +/ /g' \
129                 > ${base}/../etc/final-maps/map.${map}
130                 echo map ${map} converted.
131         done
132
133 elif [ $1 = "colldef" ]
134 then
135         awk -v tmp4=${TEMP4} '$1 == "SAME+=" && $0 !~ /legacy/ {
136                 orig=$2
137                 dest=$3
138                 gsub(/.*\./, "", orig)
139                 gsub(/.*\./, "", dest)
140                 if (orig != dest )
141                         print "LOCALES_MAPPED+=\t"$2 " "$3 > tmp4
142                 }' ${old}/Makefile
143
144         for line in $(awk '{ print $3 }' ${TEMP4}); do
145                 sed -i '' "/^SAME.*$line$/d" ${old}/Makefile
146         done
147         echo "" >> ${TEMP4}
148         for enc in ${COLLATIONS_SPECIAL}; do
149                 nname=`echo $enc | sed -e 's/_Hans//g'`
150                 sed -i '' "/^.*${nname}$/d" ${TEMP4}
151                 echo "LOCALES+= ${nname}" >> ${TEMP4}
152         done
153
154         keep=$(cat ${TEMP} | awk '{ print $2 }')
155         for original in ${keep}
156         do
157                 cp ${old}/${original}.src ${new}/
158         done
159 else  # below is everything but ctypedef
160
161         keep=$(cat ${TEMP} | awk '{ print $2 }')
162         for original in ${keep}
163         do
164                 cp ${old}/${original}.src ${new}/
165         done
166
167 fi
168
169 grep -v '^LOCALES+' ${old}/Makefile | awk "${AWKCMD}" > ${new}/Makefile
170
171 rm -f ${TEMP} ${TEMP3} ${TEMP4}