summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2025-04-05 17:37:24 -0400
committerRobby Zambito <contact@robbyzambito.me>2025-04-06 13:08:09 -0400
commit433a97fe5a973157f9cd9f62f0a62ad1a951b0c9 (patch)
treefe86004f150bbb3bb4b067e96d25d6c5af6f0cc1 /src/main.zig
parent3c935698aac68b081aaa62ef5473a194477e2578 (diff)
Move binary back to zaprus
Also clean up the args for the aux functions by computing the type instead of passing it
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
new file mode 100644
index 0000000..f43f2bd
--- /dev/null
+++ b/src/main.zig
@@ -0,0 +1,43 @@
+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.sendInitialConnection(if (message.items.len > 0) message.items else "Hello darkness my old friend", 6868, gpa);
+
+ // 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");