]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/locale/tools/finalize
Update mandoc to 20160116
[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 FULLMAP=/tmp/utf8-map
30 FULLEXTRACT=/tmp/extracted-names
31 AWKCMD="/## PLACEHOLDER/ { \
32           while ( getline line < \"${TEMP}\" ) {print line} } \
33         /## SYMPAIRS/ { \
34           while ( getline line < \"${TEMP3}\" ) {print line} } \
35         !/## / { print \$0 }"
36
37 grep '^LOCALES+' ${old}/Makefile > ${TEMP}
38
39 if [ $1 = "ctypedef" ]
40 then
41         keep=$(cat ${TEMP} | awk '{ print $2 ".src" }')
42         (cd ${old} && md5 -r ${keep} | sort) > ${TEMP2}
43         keep=$(awk '{ if ($1 != last1) print $2; last1 = $1; }' ${TEMP2})
44         for original in ${keep}
45         do
46                 cp ${old}/${original} ${new}/
47         done
48         awk '{ if ($1 == last1) { print "SYMPAIRS+=\t" last2 " " $2 } \
49         else {last1 = $1; last2 = $2}}' ${TEMP2} > ${TEMP3}
50         rm -f ${TEMP2}
51         /usr/bin/sed -E -e 's/[ ]+/ /g' \
52                 ${CLDRDIR}/posix/UTF-8.cm \
53                 > ${base}/../etc/final-maps/map.UTF-8
54         CHARMAPS="ARMSCII-8 Big5 Big5HKSCS CP1131 CP1251 \
55                 CP866 GB2312 GBK ISCII-DEV ISO8859-1 \
56                 ISO8859-13 ISO8859-15 ISO8859-2 ISO8859-4 \
57                 ISO8859-5 ISO8859-7 ISO8859-9 KOI8-R KOI8-U \
58                 PT154 SJIS US-ASCII eucCN eucJP eucKR"
59
60         # GB18030 blows up, use pre-generate Illumos version
61
62         for map in ${CHARMAPS}
63         do
64                 encoding=${map}
65                 if [ ${map} = "Big5HKSCS" ]
66                 then
67                         encoding="Big5"
68                 fi
69                 /usr/local/bin/perl ${base}/convert_map.pl \
70                         ${base}/../etc/charmaps/${map}.TXT ${encoding} \
71                         | /usr/bin/sed -E -e 's/        +/ /g' \
72                 > ${base}/../etc/final-maps/map.${map}
73                 echo map ${map} converted.
74         done
75
76 else  # below is everything but ctypedef
77
78         keep=$(cat ${TEMP} | awk '{ print $2 }')
79         for original in ${keep}
80         do
81                 cp ${old}/${original}.src ${new}/
82         done
83
84 fi
85
86 grep -v '^LOCALES+' ${old}/Makefile | awk "${AWKCMD}" > ${new}/Makefile
87
88 rm -f ${TEMP} ${TEMP3}