Add Zig Cat Example (draft)
This commit is contained in:
parent
e394029a24
commit
c26b902914
2
zig-cat/.gitignore
vendored
Normal file
2
zig-cat/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
zig-out/
|
||||||
|
.zig-cache/
|
26
zig-cat/build.zig
Normal file
26
zig-cat/build.zig
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn build(b: *std.Build) void {
|
||||||
|
const exe = b.addExecutable(.{
|
||||||
|
.name = "zig-cat",
|
||||||
|
.root_source_file = b.path("src/main.zig"),
|
||||||
|
.target = b.host,
|
||||||
|
});
|
||||||
|
|
||||||
|
b.installArtifact(exe);
|
||||||
|
|
||||||
|
const run_exe = b.addRunArtifact(exe);
|
||||||
|
const run_step = b.step("run", "Run the application");
|
||||||
|
|
||||||
|
run_step.dependOn(&run_exe.step);
|
||||||
|
|
||||||
|
const unit_tests = b.addTest(.{
|
||||||
|
.root_source_file = b.path("src/main.zig"),
|
||||||
|
.target = b.host,
|
||||||
|
});
|
||||||
|
|
||||||
|
const test_step = b.step("test", "Run unit tests");
|
||||||
|
const run_unit_tests = b.addRunArtifact(unit_tests);
|
||||||
|
|
||||||
|
test_step.dependOn(&run_unit_tests.step);
|
||||||
|
}
|
26
zig-cat/src/main.zig
Normal file
26
zig-cat/src/main.zig
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
for (std.os.argv[1..]) |file_path_sent| {
|
||||||
|
const file_path = std.mem.span(file_path_sent);
|
||||||
|
const file = try std.fs.openFileAbsolute(
|
||||||
|
file_path,
|
||||||
|
.{ .mode = .read_only },
|
||||||
|
);
|
||||||
|
defer file.close();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const rw_result = file.reader().streamUntilDelimiter(
|
||||||
|
std.io.getStdOut().writer(),
|
||||||
|
'\n',
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (rw_result) |_| {} else |_| {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std.debug.print("\n", .{});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user