1#! /bin/sh
2# Copyright(c) 2018 Thomas Wolff <towo@towo.net>
3
4echo Generating Unicode width data for newlib/libc/string/wcwidth.c
5
6cd `dirname $0`
7PATH="$PATH":.	# ensure access to uniset tool
8
9#############################################################################
10# checks and (with option -u) downloads
11
12case "$1" in
13-h)	echo "Usage: $0 [-h|-u|-i]"
14	echo "Generate width data tables ambiguous.t, combining.t, wide.t"
15	echo "from local Unicode files UnicodeData.txt, Blocks.txt, EastAsianWidth.txt."
16	echo ""
17	echo "Options:"
18	echo "  -u    download files from unicode.org first, download uniset tool"
19	echo "  -i    copy files from /usr/share/unicode/ucd first"
20	echo "  -h    show this"
21	exit
22	;;
23-u)
24	wget () {
25		ref=`basename $1`
26		ref=`ls "$ref" 2> /dev/null || echo 01-Jan-1970`
27		curl -R -O --connect-timeout 55 -z "$ref" "$1"
28	}
29
30	echo downloading uniset tool
31	wget https://www.cl.cam.ac.uk/~mgk25/download/uniset.tar.gz
32	gzip -dc uniset.tar.gz | tar xvf - uniset
33
34	echo downloading data from unicode.org
35	for data in UnicodeData.txt Blocks.txt EastAsianWidth.txt
36	do	wget http://unicode.org/Public/UNIDATA/$data
37	done
38	;;
39-i)
40	echo copying data from /usr/share/unicode/ucd
41	for data in UnicodeData.txt Blocks.txt EastAsianWidth.txt
42	do	cp /usr/share/unicode/ucd/$data .
43	done
44	;;
45esac
46
47echo checking uniset tool
48type uniset || exit 9
49
50echo checking Unicode data files
51for data in UnicodeData.txt Blocks.txt EastAsianWidth.txt
52do	if [ -r $data ]
53	then	true
54	else	echo $data not available, skipping table generation
55		exit
56	fi
57done
58
59echo generating from Unicode version `sed -e 's,[^.0-9],,g' -e 1q Blocks.txt`
60
61#############################################################################
62# table generation
63
64echo generating combining characters table
65uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B +D7B0-D7C6 +D7CB-D7FB c > combining.t
66
67echo generating ambiguous width characters table
68sh ./mkwidthA && uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c > ambiguous.t
69
70echo generating wide characters table
71sh ./mkwide
72
73#############################################################################
74# end
75