1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- // эта программа выводит все ссылки из файла links.txt, соответствующие
- // которым файлы не скачаны
- //
- // применение:
- // $ ./ldiff links.txt | wget2 -ci-
- const std = @import("std");
- const allocator = std.heap.page_allocator;
- const cwd = std.fs.cwd();
- fn rfind(link: []const u8, ch: u8) usize {
- var x: usize = 0;
- for (0..link.len) |i| {
- if (link[i] == ch)
- x = i;
- }
- return x;
- }
- pub fn main() !void {
- var args = std.process.args();
- _ = args.skip();
- const filename = args.next();
- if (filename == null)
- return error.SpecifyTheFuckingFile;
- const file = try cwd.openFile(filename.?, .{});
- defer file.close();
- const data = try allocator.alloc(u8, (try file.stat()).size);
- defer allocator.free(data);
- _ = try file.readAll(data);
- var lines = std.mem.splitAny(u8, data, "\n");
- while (lines.next()) |line| {
- if (line.len == 0) continue;
- _ = cwd.statFile(line[rfind(line, '/') + 1 ..]) catch {
- std.debug.print("{s}\n", .{line});
- };
- }
- }
|