ff24ee8fb05a6d118663cff1384af36a3f6073ae
[dragonfly.git] / tools / tools / locale / tools / finalize
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
9 usage ()
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
20 self=$(realpath $0)
21 base=$(dirname ${self})
22 old=${base}/../${1}.draft
23 new=${base}/../${1}
24 TEMP=/tmp/${1}.locales
25 TEMP2=/tmp/${1}.hashes
26 FULLMAP=/tmp/utf8-map
27 FULLEXTRACT=/tmp/extracted-names
28 AWKCMD="/## PLACEHOLDER/ { \
29           while ( getline line < \"${TEMP}\" ) {print line} } \
30         !/## PLACEHOLDER/ { print \$0 }"
31
32 grep '^LOCALES+' ${old}/Makefile > ${TEMP}
33
34 if [ $1 = "ctypedef" ]
35 then
36 keep=$(cat ${TEMP} | awk '{ print $2 ".src" }')
37 (cd ${old} && md5 -r ${keep} | sort) > ${TEMP2}
38 keep=$(awk '{ if ($1 != last1) print $2; last1 = $1; }' ${TEMP2})
39 for original in ${keep}
40 do
41         cp ${old}/${original} ${new}/
42 done
43 linx=$(awk '{ if ($1 == last1) { print "ln -s " last2 " ${new}/" $2 ";"} \
44 else {last1 = $1; last2 = $2}}' ${TEMP2})
45 eval $linx
46 rm -f ${TEMP2}
47         /usr/bin/sed -E -e 's/[ ]+/ /g' \
48                 ${CLDRDIR}/posix/UTF-8.cm \
49                 > ${base}/../etc/final-maps/map.UTF-8
50 CHARMAPS="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
58 for map in ${CHARMAPS}
59 do
60 encoding=${map}
61 if [ ${map} = "Big5HKSCS" ]
62 then
63 encoding="Big5"
64 fi
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.
70 done
71
72 else  # below is everything but ctypedef
73
74 keep=$(cat ${TEMP} | awk '{ print $2 }')
75 for original in ${keep}
76 do
77         cp ${old}/${original}.src ${new}/
78 done
79
80 fi
81
82 grep -v '^LOCALES+' ${old}/Makefile | awk "${AWKCMD}" > ${new}/Makefile
83
84 rm -f ${TEMP}