Add helpers for parsing.
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
96a49994f5
commit
00803fd554
2 changed files with 29 additions and 0 deletions
16
src/lib/args.zig
Normal file
16
src/lib/args.zig
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
const std = @import("std");
|
||||
const process = std.process;
|
||||
const print = std.debug.print;
|
||||
|
||||
pub fn getFirstArg() [:0]const u8 {
|
||||
var args = process.args();
|
||||
defer args.deinit();
|
||||
|
||||
// Skip the first argument since it's the name of the program.
|
||||
_ = args.skip();
|
||||
|
||||
return args.next() orelse {
|
||||
print("Provide at least one input\n", .{});
|
||||
process.exit(1);
|
||||
};
|
||||
}
|
||||
13
src/lib/files.zig
Normal file
13
src/lib/files.zig
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
const std = @import("std");
|
||||
const fs = std.fs;
|
||||
const File = std.fs.File;
|
||||
|
||||
pub fn openForReading(rel_path: []const u8) !File {
|
||||
var abs_path_buff: [fs.max_path_bytes]u8 = undefined;
|
||||
const abs_path = try fs.realpath(rel_path, &abs_path_buff);
|
||||
return try fs.openFileAbsolute(abs_path, File.OpenFlags{ .mode = .read_only });
|
||||
}
|
||||
|
||||
pub fn readLine(file: File, buf: []u8) ![]u8 {
|
||||
return try file.reader().readUntilDelimiter(buf, '\n');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue