diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-05-24 23:02:04 +0300 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-05-24 23:02:04 +0300 |
commit | 70e338981360fe65ded5b997f6394f09826ecb51 (patch) | |
tree | 0a746c97677afd613faa99d72c7efb83bf1359ea /src | |
download | zrcc-70e338981360fe65ded5b997f6394f09826ecb51.tar.xz |
Initial commit
Diffstat (limited to 'src')
-rw-r--r-- | src/main.zig | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..1b8f702 --- /dev/null +++ b/src/main.zig @@ -0,0 +1,59 @@ +const std = @import("std"); +const adler32 = std.hash.Adler32; +const openFlags = std.fs.File.OpenFlags{ + .read = true, + .write = false, + .lock = std.fs.File.Lock.None, +}; + +fn dump(args: [][]u8) u8 { + if (args.len < 3) { + std.debug.warn("Usage: {} [subcommand] [options]\n", .{args[0]}); + return 255; + } + + var file = std.fs.openFileAbsolute(args[2], openFlags) catch { + std.debug.warn("Cannot open file {}\n", .{args[2]}); + return 255; + }; + defer file.close(); + + var buffer: [16]u8 = undefined; + var r: u64 = undefined; + while (true) { + r = file.read(&buffer) catch { + break; + }; + if (r <= 0) + break; + + for (buffer[0..r]) |c| { + std.debug.warn("0x{x:2} ", .{c}); + } + std.debug.warn(" -- {}\n", .{r}); + } + + return 0; +} + +fn help(args: [][]u8) u8 { + std.debug.warn("Usage: {} [subcommand] [options]\n", .{args[0]}); + return if (args.len < 2) 255 else 0; +} + +pub fn main() anyerror!u8 { + var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); + defer arena.deinit(); + + std.debug.warn("All your codebase are belong to us.\n\n", .{}); + + const args = try std.process.argsAlloc(&arena.allocator); + if (args.len < 2) { + return help(args); + } + + return switch (adler32.hash(args[1])) { + adler32.hash("dump") => dump(args), + else => help(args), + }; +} |