mirror of
https://git.robbyzambito.me/zaprus
synced 2025-12-21 16:54:49 +00:00
42 lines
1.1 KiB
Zig
42 lines
1.1 KiB
Zig
const is_debug = builtin.mode == .Debug;
|
|
|
|
/// This creates a debug allocator that can only be referenced in debug mode.
|
|
/// You should check for is_debug around every reference to dba.
|
|
var dba: DebugAllocator =
|
|
if (is_debug)
|
|
DebugAllocator.init
|
|
else
|
|
@compileError("Should not use debug allocator in release mode");
|
|
|
|
pub fn main() !void {
|
|
defer if (is_debug) {
|
|
_ = dba.deinit();
|
|
};
|
|
|
|
const gpa = if (is_debug) dba.allocator() else std.heap.smp_allocator;
|
|
|
|
const args = try std.process.argsAlloc(gpa);
|
|
defer std.process.argsFree(gpa, args);
|
|
|
|
var message = ArrayList(u8).init(gpa);
|
|
defer message.deinit();
|
|
|
|
for (args[1..], 0..) |arg, i| {
|
|
try message.appendSlice(arg);
|
|
if (i < args.len - 1)
|
|
try message.append(' ');
|
|
}
|
|
|
|
try Saprus.init();
|
|
defer Saprus.deinit();
|
|
|
|
try Saprus.sendRelay(if (message.items.len > 0) message.items else "Hello darkness my old friend", gpa);
|
|
}
|
|
|
|
const builtin = @import("builtin");
|
|
const std = @import("std");
|
|
const DebugAllocator = std.heap.DebugAllocator(.{});
|
|
const ArrayList = std.ArrayList;
|
|
|
|
const Saprus = @import("./saprus.zig");
|