File: tounimap2h.lua

package info (click to toggle)
xdvik-ja 22.84.16-j1.40+t1lib-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 16,628 kB
  • ctags: 10,310
  • sloc: ansic: 88,999; sh: 5,309; makefile: 1,031; perl: 245; lisp: 244
file content (58 lines) | stat: -rw-r--r-- 1,502 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
-- usage: tounimap2h.lua <ToUniCode> <function name> <end cid number>

local result = {}
print("/* This file was generated by tounimap2h.lua.\n"
	     .. "Used ToUnicode table is: " .. arg[1] .. ".*/\n")
local line = io.read("*l")
local function info(a) io.stderr:write(a) end

local function bfchar()
   info('*')
   line = io.read("*l")
   while  line and line ~= "endbfchar" do
      if string.len(line) == 13 then
	 local cid = tonumber(string.sub(line,2,5), 16);
	 local code = tonumber(string.sub(line,9,12), 16);
	 result[cid] = code
      end
      line = io.read()
   end
end
local function bfrange()
   info('+')
   line = io.read("*l")
   while  line and line ~= "endbfrange" do
      if string.len(line) == 20 then
	 local cidb = tonumber(string.sub(line,2,5), 16);
	 local cide = tonumber(string.sub(line,9,12), 16);
	 local code = tonumber(string.sub(line,16,19), 16);
	 for x = cidb, cide do result[x] = code+x-cidb end
      end
      line = io.read()
   end
end

while  line do
   if string.match(line,"beginbfchar") then
      bfchar()
   elseif string.match(line,"beginbfrange") then
      bfrange()
   elseif line~="" then
      info("-")
   end
   line = io.read()
end

info("\n")

print("static unsigned short " .. arg[2] .. "2uni_table[] = {")

for x=0,arg[3] do
   if x%10==0 then io.write("  ") end
   io.write((result[x] or 0) .. ', ')
   if x%10 == 9 then io.write("\n")  end
end

print("}; \n")

print("#define " .. arg[2] .. "2uni(cid) (" .. arg[2] .. "2uni_table[cid])\n")