-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.zig
More file actions
28 lines (21 loc) · 792 Bytes
/
example.zig
File metadata and controls
28 lines (21 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const std = @import("std");
const dtree = @import("dtree");
pub fn main(init: std.process.Init) !void {
const io = init.io;
const gpa = init.gpa;
var args = try init.minimal.args.iterateAllocator(gpa);
defer args.deinit();
_ = args.skip();
const path = args.next() orelse return error.MissingArgument;
const file = if (std.fs.path.isAbsolute(path))
try std.Io.Dir.openFileAbsolute(io, path, .{})
else
try std.Io.Dir.cwd().openFile(io, path, .{});
defer file.close(io);
const fdt = try dtree.Reader.initFile(gpa, io, file);
defer fdt.deinit();
var stdout_buf: [4096]u8 = undefined;
var stdout = std.Io.File.stdout().writer(io, &stdout_buf);
try fdt.writeDts(&stdout.interface);
try stdout.interface.flush();
}