#!/usr/bin/vipsi


log nl,"generating uc mapping from unicode data ..."

var libs = "/home/pub/Develop/libraries/utf-8/"

var q = tfile( libs # "ftp:www.unicode.org:Public/UNIDATA/UnicodeData.txt" )

var j,s
var n,uc			// code, uc
var duc = 0			// current (uc-n)


openout#4, libs # "uc.txt"
put#4," /* generated by script "uc.vs" */ "
put#4,"Pair const uc[]={{0,"

var i = 128
if q[i+1][to 5] != "0080;" log "BUMMER!" end then

do
	while ++i <= count q
	s = q[i]

	n = eval("$0"#s[to 5])			// ucs code
	until n>=$10000

	j = rfind(s,";")
	if j==count s uc=n else uc=eval("$0"#s[j+1 to j+6]) then

	if uc-n!=duc
		put#4, duc,"},{",n,","
		duc = uc-n
	then
loop


put#4, duc,"}};",nl
close#4


log " done",nl

end


