this repo has no description

+173
+2
.gitignore
··· 1 + .zig-cache/ 2 + zig-out/
+47
build.zig
··· 1 + const std = @import("std"); 2 + 3 + pub fn build(b: *std.Build) void { 4 + const target = b.standardTargetOptions(.{}); 5 + const optimize = b.standardOptimizeOption(.{}); 6 + 7 + const exe_mod = b.createModule(.{ 8 + .root_source_file = b.path("src/main.zig"), 9 + .target = target, 10 + .optimize = optimize, 11 + }); 12 + 13 + const io_dep = b.dependency("ourio", .{ .optimize = optimize, .target = target }); 14 + const io_mod = io_dep.module("ourio"); 15 + exe_mod.addImport("ourio", io_mod); 16 + 17 + const zeit_dep = b.dependency("zeit", .{ .optimize = optimize, .target = target }); 18 + const zeit_mod = zeit_dep.module("zeit"); 19 + exe_mod.addImport("zeit", zeit_mod); 20 + 21 + const exe = b.addExecutable(.{ 22 + .name = "lsr", 23 + .root_module = exe_mod, 24 + }); 25 + 26 + b.installArtifact(exe); 27 + 28 + const run_cmd = b.addRunArtifact(exe); 29 + 30 + run_cmd.step.dependOn(b.getInstallStep()); 31 + 32 + if (b.args) |args| { 33 + run_cmd.addArgs(args); 34 + } 35 + 36 + const run_step = b.step("run", "Run the app"); 37 + run_step.dependOn(&run_cmd.step); 38 + 39 + const exe_unit_tests = b.addTest(.{ 40 + .root_module = exe_mod, 41 + }); 42 + 43 + const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); 44 + 45 + const test_step = b.step("test", "Run unit tests"); 46 + test_step.dependOn(&run_exe_unit_tests.step); 47 + }
+56
build.zig.zon
··· 1 + .{ 2 + // This is the default name used by packages depending on this one. For 3 + // example, when a user runs `zig fetch --save <url>`, this field is used 4 + // as the key in the `dependencies` table. Although the user can choose a 5 + // different name, most users will stick with this provided value. 6 + // 7 + // It is redundant to include "zig" in this name because it is already 8 + // within the Zig package namespace. 9 + .name = .lsr, 10 + 11 + // This is a [Semantic Version](https://semver.org/). 12 + // In a future version of Zig it will be used for package deduplication. 13 + .version = "0.0.0", 14 + 15 + // Together with name, this represents a globally unique package 16 + // identifier. This field is generated by the Zig toolchain when the 17 + // package is first created, and then *never changes*. This allows 18 + // unambiguous detection of one package being an updated version of 19 + // another. 20 + // 21 + // When forking a Zig project, this id should be regenerated (delete the 22 + // field and run `zig build`) if the upstream project is still maintained. 23 + // Otherwise, the fork is *hostile*, attempting to take control over the 24 + // original project's identity. Thus it is recommended to leave the comment 25 + // on the following line intact, so that it shows up in code reviews that 26 + // modify the field. 27 + .fingerprint = 0x495d173af9afcd7, // Changing this has security and trust implications. 28 + 29 + // Tracks the earliest Zig version that the package considers to be a 30 + // supported use case. 31 + .minimum_zig_version = "0.14.0", 32 + 33 + // This field is optional. 34 + // Each dependency must either provide a `url` and `hash`, or a `path`. 35 + // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. 36 + // Once all dependencies are fetched, `zig build` no longer requires 37 + // internet connectivity. 38 + .dependencies = .{ 39 + .ourio = .{ 40 + .url = "git+https://github.com/rockorager/ourio#6ed0e45a772f6a7241db1663085db3f813bf3932", 41 + .hash = "ourio-0.0.0-_s-z0agIAgD_Ih6DEjzDGxy5EP9K1i_xye_VacvLzgY5", 42 + }, 43 + .zeit = .{ 44 + .url = "git+https://github.com/rockorager/zeit#4496d1c40b2223c22a1341e175fc2ecd94cc0de9", 45 + .hash = "zeit-0.6.0-5I6bk1J1AgA13rteb6E0steXiOUKBYTzJZMMIuK9oEmb", 46 + }, 47 + }, 48 + .paths = .{ 49 + "build.zig", 50 + "build.zig.zon", 51 + "src", 52 + // For example... 53 + //"LICENSE", 54 + //"README.md", 55 + }, 56 + }
+68
src/main.zig
··· 1 + const std = @import("std"); 2 + const builtin = @import("builtin"); 3 + const io = @import("ourio"); 4 + 5 + const linux = std.os.linux; 6 + 7 + pub fn main() !void { 8 + var debug_allocator: std.heap.DebugAllocator(.{}) = .init; 9 + const gpa, const is_debug = gpa: { 10 + break :gpa switch (builtin.mode) { 11 + .Debug, .ReleaseSafe => .{ debug_allocator.allocator(), true }, 12 + .ReleaseFast, .ReleaseSmall => .{ std.heap.smp_allocator, false }, 13 + }; 14 + }; 15 + defer if (is_debug) { 16 + _ = debug_allocator.deinit(); 17 + }; 18 + 19 + var arena = std.heap.ArenaAllocator.init(gpa); 20 + defer arena.deinit(); 21 + 22 + var ring: io.Ring = try .init(arena.allocator(), 64); 23 + defer ring.deinit(); 24 + 25 + // TODO: implement openat in ourio 26 + var cwd = try std.fs.cwd().openDir(".", .{ .iterate = true }); 27 + defer cwd.close(); 28 + 29 + var results: std.ArrayListUnmanaged(*Entry) = .empty; 30 + 31 + var iter = cwd.iterate(); 32 + while (try iter.next()) |dirent| { 33 + const nameZ = try arena.allocator().dupeZ(u8, dirent.name); 34 + const entry = try arena.allocator().create(Entry); 35 + entry.* = .{ .name = nameZ, .kind = dirent.kind, .statx = undefined }; 36 + try results.append(arena.allocator(), entry); 37 + _ = try ring.stat(nameZ, &entry.statx, .{ .cb = onCompletion }); 38 + } 39 + 40 + try ring.run(.until_done); 41 + 42 + var output: std.ArrayListUnmanaged(u8) = .empty; 43 + var writer = output.writer(arena.allocator()); 44 + for (results.items) |entry| { 45 + try writer.print("{s}\r\n", .{entry.name}); 46 + } 47 + 48 + try std.io.getStdOut().writeAll(output.items); 49 + } 50 + 51 + const Entry = struct { 52 + name: [:0]const u8, 53 + kind: std.fs.File.Kind, 54 + statx: io.Statx, 55 + 56 + fn lessThan(_: void, lhs: *Entry, rhs: *Entry) bool { 57 + return std.ascii.orderIgnoreCase(lhs.name, rhs.name).compare(.lt); 58 + } 59 + }; 60 + 61 + fn onCompletion(_: *io.Ring, task: io.Task) anyerror!void { 62 + const result = task.result.?; 63 + 64 + _ = result.statx catch |err| { 65 + std.log.err("stat error: {}", .{err}); 66 + return; 67 + }; 68 + }