summaryrefslogtreecommitdiff
path: root/src/main.zig
blob: 1b3b689833c86c8e895ce51805ff9643251b4cdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const std = @import("std");
const Io = std.Io;

pub fn main(init: std.process.Init) !void {
    // This is appropriate for anything that lives as long as the process.
    const arena: std.mem.Allocator = init.arena.allocator();

    // Accessing command line arguments:
    const args = try init.minimal.args.toSlice(arena);
    const filepath = args[0];
    const filename = std.fs.path.basename(filepath);

    std.log.debug("executable name: {s}", .{filename});

    const io = init.io;
    var words = try tokenizeIntoArraylist(arena, filename);

    const command = try words.toOwnedSlice(arena);

    return std.process.replace(io, .{
        .argv = command,
    });
}

fn tokenizeIntoArraylist(gpa: std.mem.Allocator, buffer: []const u8) !std.ArrayList([]const u8) {
    var it = std.mem.tokenizeScalar(u8, buffer, ' ');

    var words = std.ArrayList([]const u8).empty;

    while (it.next()) |word| {
        try words.append(gpa, word);
    }

    return words;
}