Update configuration paths and enhance allocator handling in main.zig
This commit is contained in:
40
src/main.zig
40
src/main.zig
@@ -1,8 +1,46 @@
|
||||
const zocket = @import("zocket");
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub fn main(init: std.process.Init) !void
|
||||
{
|
||||
_ = init;
|
||||
const io = init.io;
|
||||
|
||||
std.debug.print("{any}\n", .{builtin.mode});
|
||||
|
||||
if (builtin.mode == .Debug)
|
||||
{
|
||||
var arena: std.heap.DebugAllocator(.{}) = .init;
|
||||
defer _ = arena.deinit();
|
||||
|
||||
try run(io, arena.allocator(), "zocket/config.toml");
|
||||
}
|
||||
else
|
||||
{
|
||||
var arena = std.heap.ArenaAllocator.init(std.heap.smp_allocator);
|
||||
defer arena.deinit();
|
||||
|
||||
const allocator = arena.allocator();
|
||||
|
||||
var tmpArena = std.heap.ArenaAllocator.init(std.heap.smp_allocator);
|
||||
const tmpAllocator = tmpArena.allocator();
|
||||
|
||||
const exe = try std.process.executableDirPathAlloc(io, tmpAllocator);
|
||||
const path = try std.fs.path.join(allocator, &.{ exe, "zocket/config.toml" });
|
||||
|
||||
tmpArena.deinit();
|
||||
|
||||
try run(io, allocator, path);
|
||||
}
|
||||
}
|
||||
|
||||
fn run(io: std.Io, allocator: std.mem.Allocator, path: []const u8) !void
|
||||
{
|
||||
const parsed = try zocket.config.parse(io, allocator, path);
|
||||
defer parsed.deinit();
|
||||
|
||||
const configuration = parsed.value;
|
||||
|
||||
std.debug.print("{any}", .{configuration});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user