Compare commits

...

1 Commits

Author SHA1 Message Date
Rekai Nyangadzayi Musuka 3aa48d83fb chore: switch from zig-toml to tomlz 2022-12-01 14:14:09 -04:00
5 changed files with 20 additions and 25 deletions

6
.gitmodules vendored
View File

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

View File

@ -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");

1
lib/tomlz Submodule

@ -0,0 +1 @@
Subproject commit a0337d65a07d285efe5d5b060c7ec1aa0035a2b9

@ -1 +0,0 @@
Subproject commit 016b8bcf98e50ae9408f6a9606bbec5a9bc6f677

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