ldiff.zig 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // эта программа выводит все ссылки из файла links.txt, соответствующие
  2. // которым файлы не скачаны
  3. //
  4. // применение:
  5. // $ ./ldiff links.txt | wget2 -ci-
  6. const std = @import("std");
  7. const allocator = std.heap.page_allocator;
  8. const cwd = std.fs.cwd();
  9. fn rfind(link: []const u8, ch: u8) usize {
  10. var x: usize = 0;
  11. for (0..link.len) |i| {
  12. if (link[i] == ch)
  13. x = i;
  14. }
  15. return x;
  16. }
  17. pub fn main() !void {
  18. var args = std.process.args();
  19. _ = args.skip();
  20. const filename = args.next();
  21. if (filename == null)
  22. return error.SpecifyTheFuckingFile;
  23. const file = try cwd.openFile(filename.?, .{});
  24. defer file.close();
  25. const data = try allocator.alloc(u8, (try file.stat()).size);
  26. defer allocator.free(data);
  27. _ = try file.readAll(data);
  28. var lines = std.mem.splitAny(u8, data, "\n");
  29. while (lines.next()) |line| {
  30. if (line.len == 0) continue;
  31. _ = cwd.statFile(line[rfind(line, '/') + 1 ..]) catch {
  32. std.debug.print("{s}\n", .{line});
  33. };
  34. }
  35. }