diff options
Diffstat (limited to '')
| -rw-r--r-- | codegen/upper.zig | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/codegen/upper.zig b/codegen/upper.zig new file mode 100644 index 0000000..6fea608 --- /dev/null +++ b/codegen/upper.zig | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | pub fn main() !void { | ||
| 5 | var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); | ||
| 6 | defer arena.deinit(); | ||
| 7 | const allocator = arena.allocator(); | ||
| 8 | |||
| 9 | // Process UnicodeData.txt | ||
| 10 | var in_file = try std.fs.cwd().openFile("data/unicode/UnicodeData.txt", .{}); | ||
| 11 | defer in_file.close(); | ||
| 12 | var in_buf = std.io.bufferedReader(in_file.reader()); | ||
| 13 | const in_reader = in_buf.reader(); | ||
| 14 | |||
| 15 | var args_iter = try std.process.argsWithAllocator(allocator); | ||
| 16 | defer args_iter.deinit(); | ||
| 17 | _ = args_iter.skip(); | ||
| 18 | const output_path = args_iter.next() orelse @panic("No output file arg!"); | ||
| 19 | |||
| 20 | const compressor = std.compress.deflate.compressor; | ||
| 21 | var out_file = try std.fs.cwd().createFile(output_path, .{}); | ||
| 22 | defer out_file.close(); | ||
| 23 | var out_comp = try compressor(allocator, out_file.writer(), .{ .level = .best_compression }); | ||
| 24 | defer out_comp.deinit(); | ||
| 25 | const writer = out_comp.writer(); | ||
| 26 | |||
| 27 | const endian = builtin.cpu.arch.endian(); | ||
| 28 | var line_buf: [4096]u8 = undefined; | ||
| 29 | |||
| 30 | lines: while (try in_reader.readUntilDelimiterOrEof(&line_buf, '\n')) |line| { | ||
| 31 | if (line.len == 0) continue; | ||
| 32 | |||
| 33 | var field_iter = std.mem.splitScalar(u8, line, ';'); | ||
| 34 | var cps: [2]u24 = undefined; | ||
| 35 | |||
| 36 | var i: usize = 0; | ||
| 37 | while (field_iter.next()) |field| : (i += 1) { | ||
| 38 | switch (i) { | ||
| 39 | 0 => cps[0] = try std.fmt.parseInt(u24, field, 16), | ||
| 40 | |||
| 41 | 12 => { | ||
| 42 | // Simple uppercase mapping | ||
| 43 | if (field.len == 0) continue :lines; | ||
| 44 | cps[1] = try std.fmt.parseInt(u24, field, 16); | ||
| 45 | }, | ||
| 46 | |||
| 47 | 2 => if (line[0] == '<') continue :lines, | ||
| 48 | |||
| 49 | else => {}, | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | for (&cps) |cp| try writer.writeInt(u24, cp, endian); | ||
| 54 | } | ||
| 55 | |||
| 56 | try writer.writeInt(u24, 0, endian); | ||
| 57 | try out_comp.flush(); | ||
| 58 | } | ||