chore: switch from zig-toml to tomlz

This commit is contained in:
2022-12-01 14:14:09 -04:00
parent ddc54e2977
commit 5989f05faf
5 changed files with 20 additions and 25 deletions

View File

@@ -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;
}
}