#!/usr/bin/vipsi


log nl,"generating lc 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,lc			// code, uc, lc
var dlc = 0			// current (lc-n)


openout#5, libs # "lc.txt"
put#5," /* generated by script "lc.vs" */ "
put#5,"Pair const lc[]={{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,";")
	s = s[to j-1]
	j = rfind(s,";")
	if j==count s lc=n else lc=eval("$0"#s[j+1 to j+6]) then

	if lc-n!=dlc
		put#5, dlc,"},{",n,","
		dlc = lc-n
	then
loop


put#5, dlc,"}};",nl
close#5

log " done",nl

end


