1 invalid_data
= "007E7E7E4E367A7A76766E6E7E6E7E00";
2 nonexistent_data
= "00540240024002400240024002402A00";
29 known_args
["input"] = true;
30 known_args
["output"] = true;
31 known_args
["spacehack"] = true;
37 for k
, v
in ipairs(arg
) do
38 name
, value
= string.match(v
, "([%w_-]+)=(.*)");
39 if not name
or not value
then
40 error("Bad argument: '" .. v
.. "'.");
45 for k
, v
in pairs(args
) do
46 if not known_args
[k
] then
47 print("Warning: Unknown option '" .. k
.. "'.");
52 -- This is JPC-RR embedded Selfstanding Lua interpretter.
53 print("Detected environment: JPC-RR embedded Lua interpretter");
54 if not args
["input"] or not args
["output"] then
55 error("Syntax: input=<input> and output=<output> required");
57 tmpfile
= io
.open_read(args
["input"]);
58 infile
= tmpfile
:text();
59 outfile
= io
.open_write(args
["output"]);
61 -- Assume reference implementation or compatible.
62 print("Detected environment: Reference Lua interpretter or compatible");
63 if not args
["input"] or not args
["output"] then
64 error("Syntax: input=<input> and output=<output> required");
66 infile
= io
.open(args
["input"], "r");
67 outfile
= io
.open(args
["output"], "w");
70 if args
["spacehack"] then
74 write_data_to_file
= function(data
)
78 read_data_from_file
= function()
82 parsenumber
= function(hexnumber
)
83 local n
= tonumber("0x" .. hexnumber
);
85 error("Bad number " .. hexnumber
);
90 hex_to_member_data
= function(codepoint
, hex
)
91 local s
= "!BEGIN " .. tostring(codepoint
) .. "\n";
93 s
= s
.. "+\"*" -- width 8
94 elseif #hex
== 64 then
95 s
= s
.. "+\"2" -- width 16
97 error("Unknown font format " .. (#hex
) .. ".");
100 for i
= 0,(#hex
- 1),8 do
101 local c1
, c2
, c3
, c4
, c5
, c6
, c7
, c8
;
102 c1
= hexes
[string.byte(hex
, i
+ 1)];
103 c2
= hexes
[string.byte(hex
, i
+ 2)];
104 c3
= hexes
[string.byte(hex
, i
+ 3)];
105 c4
= hexes
[string.byte(hex
, i
+ 4)];
106 c5
= hexes
[string.byte(hex
, i
+ 5)];
107 c6
= hexes
[string.byte(hex
, i
+ 6)];
108 c7
= hexes
[string.byte(hex
, i
+ 7)];
109 c8
= hexes
[string.byte(hex
, i
+ 8)];
111 val
= c2
* 268435456 + c1
* 16777216 + c4
* 1048576 + c3
* 65536 +
112 c6
* 4096 + c5
* 256 + c8
* 16 + c7
;
113 local x1
, x2
, x3
, x4
, x5
;
115 val
= (val
- x5
) / 93;
117 val
= (val
- x4
) / 93;
119 val
= (val
- x3
) / 93;
121 val
= (val
- x2
) / 93;
123 s
= s
.. string.char(x1
+ 66, x2
+ 34, x3
+ 34, x4
+ 34, x5
+ 34);
128 local codepoints
= 0;
130 write_codepoint
= function(codepoint
, hex
)
131 write_data_to_file(hex_to_member_data(codepoint
, hex
));
132 codepoints
= codepoints
+ 1;
133 if codepoints
% 1000 == 0 then
134 print("Wrote " .. codepoints
.. " codepoints");
139 write_data_to_file("JRSR\n");
140 write_codepoint("invalid", invalid_data
);
141 write_codepoint("nonexistent", nonexistent_data
);
143 write_codepoint(32, "00000000000000000000000000000000");
146 local line
= read_data_from_file();
149 sep
= string.find(line
, ":");
151 error("Badly formatted line (" .. line
.. ")");
154 code
= parsenumber(string.sub(line
, 1, sep
- 1));
155 hexes
= string.sub(line
, sep
+ 1);
156 if code
~= 32 or not spacehack
then
157 write_codepoint(code
, hexes
);
160 line
= read_data_from_file();
164 write_data_to_file("!END\n");
165 print("Converted " .. (codepoints
- 2) .. " codepoints");