summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
new file mode 100644
index 0000000..1b3b689
--- /dev/null
+++ b/src/main.zig
@@ -0,0 +1,35 @@
1const std = @import("std");
2const Io = std.Io;
3
4pub fn main(init: std.process.Init) !void {
5 // This is appropriate for anything that lives as long as the process.
6 const arena: std.mem.Allocator = init.arena.allocator();
7
8 // Accessing command line arguments:
9 const args = try init.minimal.args.toSlice(arena);
10 const filepath = args[0];
11 const filename = std.fs.path.basename(filepath);
12
13 std.log.debug("executable name: {s}", .{filename});
14
15 const io = init.io;
16 var words = try tokenizeIntoArraylist(arena, filename);
17
18 const command = try words.toOwnedSlice(arena);
19
20 return std.process.replace(io, .{
21 .argv = command,
22 });
23}
24
25fn tokenizeIntoArraylist(gpa: std.mem.Allocator, buffer: []const u8) !std.ArrayList([]const u8) {
26 var it = std.mem.tokenizeScalar(u8, buffer, ' ');
27
28 var words = std.ArrayList([]const u8).empty;
29
30 while (it.next()) |word| {
31 try words.append(gpa, word);
32 }
33
34 return words;
35}