From 3aa48d83fb6d15f480749dac74619a7505e5dac0 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Thu, 1 Dec 2022 14:14:09 -0400 Subject: [PATCH] chore: switch from zig-toml to tomlz --- .gitmodules | 6 +++--- build.zig | 3 +-- lib/tomlz | 1 + lib/zig-toml | 1 - src/config.zig | 34 +++++++++++++++------------------- 5 files changed, 20 insertions(+), 25 deletions(-) create mode 160000 lib/tomlz delete mode 160000 lib/zig-toml diff --git a/.gitmodules b/.gitmodules index 78bd5b0..1919140 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,6 +10,6 @@ [submodule "lib/zig-datetime"] path = lib/zig-datetime url = https://github.com/frmdstryr/zig-datetime -[submodule "lib/zig-toml"] - path = lib/zig-toml - url = https://github.com/aeronavery/zig-toml +[submodule "lib/tomlz"] + path = lib/tomlz + url = https://github.com/mattyhall/tomlz diff --git a/build.zig b/build.zig index ccfb38a..6481dcc 100644 --- a/build.zig +++ b/build.zig @@ -31,14 +31,13 @@ pub fn build(b: *std.build.Builder) void { exe.addPackagePath("datetime", "lib/zig-datetime/src/main.zig"); // Bitfield type from FlorenceOS: https://github.com/FlorenceOS/ - // exe.addPackage(.{ .name = "bitfield", .path = .{ .path = "lib/util/bitfield.zig" } }); exe.addPackagePath("bitfield", "lib/util/bitfield.zig"); // Argument Parsing Library exe.addPackagePath("clap", "lib/zig-clap/clap.zig"); // TOML Library - exe.addPackagePath("toml", "lib/zig-toml/src/toml.zig"); + exe.addPackagePath("tomlz", "lib/tomlz/src/main.zig"); // OpenGL 3.3 Bindings exe.addPackagePath("gl", "lib/gl.zig"); diff --git a/lib/tomlz b/lib/tomlz new file mode 160000 index 0000000..a0337d6 --- /dev/null +++ b/lib/tomlz @@ -0,0 +1 @@ +Subproject commit a0337d65a07d285efe5d5b060c7ec1aa0035a2b9 diff --git a/lib/zig-toml b/lib/zig-toml deleted file mode 160000 index 016b8bc..0000000 --- a/lib/zig-toml +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 016b8bcf98e50ae9408f6a9606bbec5a9bc6f677 diff --git a/src/config.zig b/src/config.zig index 329d65d..b62a764 100644 --- a/src/config.zig +++ b/src/config.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const toml = @import("toml"); +const tomlz = @import("tomlz"); const Allocator = std.mem.Allocator; @@ -58,29 +58,25 @@ pub fn load(allocator: Allocator, file_path: []const u8) !void { const contents = try config_file.readToEndAlloc(allocator, try config_file.getEndPos()); defer allocator.free(contents); - var parser = try toml.parseFile(allocator, file_path); - defer parser.deinit(); - - const table = try parser.parse(); - defer table.deinit(); + var table = try tomlz.parse(allocator, contents); + defer table.deinit(allocator); // TODO: Report unknown config options - - if (table.keys.get("Host")) |host| { - if (host.Table.keys.get("win_scale")) |scale| state.host.win_scale = scale.Integer; - if (host.Table.keys.get("vsync")) |vsync| state.host.vsync = vsync.Boolean; - if (host.Table.keys.get("mute")) |mute| state.host.mute = mute.Boolean; + if (table.getTable("Host")) |host| { + if (host.getInteger("win_scale")) |scale| state.host.win_scale = scale; + if (host.getBool("vsync")) |vsync| state.host.vsync = vsync; + if (host.getBool("mute")) |mute| state.host.mute = mute; } - if (table.keys.get("Guest")) |guest| { - if (guest.Table.keys.get("audio_sync")) |sync| state.guest.audio_sync = sync.Boolean; - if (guest.Table.keys.get("video_sync")) |sync| state.guest.video_sync = sync.Boolean; - if (guest.Table.keys.get("force_rtc")) |forced| state.guest.force_rtc = forced.Boolean; - if (guest.Table.keys.get("skip_bios")) |skip| state.guest.skip_bios = skip.Boolean; + if (table.getTable("Guest")) |guest| { + if (guest.getBool("audio_sync")) |sync| state.guest.audio_sync = sync; + if (guest.getBool("video_sync")) |sync| state.guest.video_sync = sync; + if (guest.getBool("force_rtc")) |forced| state.guest.force_rtc = forced; + if (guest.getBool("skip_bios")) |skip| state.guest.skip_bios = skip; } - if (table.keys.get("Debug")) |debug| { - if (debug.Table.keys.get("cpu_trace")) |trace| state.debug.cpu_trace = trace.Boolean; - if (debug.Table.keys.get("unhandled_io")) |unhandled| state.debug.unhandled_io = unhandled.Boolean; + if (table.getTable("Debug")) |debug| { + if (debug.getBool("cpu_trace")) |trace| state.debug.cpu_trace = trace; + if (debug.getBool("unhandled_io")) |unhandled| state.debug.unhandled_io = unhandled; } }