From 28990d9cb11de4dc35f4f141fd002256c39b0032 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Fri, 6 May 2022 00:51:04 +0200 Subject: [PATCH] Main "all-in-one" program source code. --- src/main.zig | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main.zig diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..6451016 --- /dev/null +++ b/src/main.zig @@ -0,0 +1,30 @@ +const std = @import("std"); +const eq = std.mem.eql; + +const ls = @import("ls.zig"); +const cat = @import("cat.zig"); + +const lib = @import("lib.zig"); + +fn help() void { + const help_string = + \\ + \\ toying with a single tool: zig build-exe ls.zig + \\ (currently ± working tools: cat, ls) + \\ + \\ global compilation: zig build-exe main.zig + \\ -> produces "main" that includes all tools + \\ you can invoke each tool by creating a symbolic link to "main" + \\ ex: ln -s main ls <- now you have "ls" working as your well-known "ls" :) + ; + lib.print("{s}\n", .{help_string}); +} + +pub fn main() !void { + const args = try std.process.argsAlloc(std.heap.page_allocator); + const bname = std.fs.path.basename(args[0]); + + if (eq(u8, bname, "ls")) { try ls.main(); } + else if (eq(u8, bname, "cat")) { try cat.main(); } + else { help(); } +}