| 1 |
const std = @import("std"); |
| 2 |
const Io = std.Io; |
| 3 |
|
| 4 |
pub fn main(init: std.process.Init) !void { |
| 5 |
|
| 6 |
const arena: std.mem.Allocator = init.arena.allocator(); |
| 7 |
|
| 8 |
|
| 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 |
|
| 25 |
fn 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 |
} |