From 57ead0820a95f61324a4609e797ba0e0a11039e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Mon, 31 Jul 2023 21:20:17 +0900 Subject: [PATCH] =?UTF-8?q?ls=20-l=E3=81=AE=E9=80=B2=E6=AD=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libtoki | 2 +- ls.zig | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libtoki b/libtoki index 436ccb7..9cec391 160000 --- a/libtoki +++ b/libtoki @@ -1 +1 @@ -Subproject commit 436ccb7ea99abd63cdab0d442c82e741d0e27bab +Subproject commit 9cec39129a5fcfaa2840fab0f63d85cecdcff11e diff --git a/ls.zig b/ls.zig index d8d6674..7384a35 100644 --- a/ls.zig +++ b/ls.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const toki = @import("libtoki/src/main.zig"); const fs = std.fs; const io = std.io; @@ -14,7 +15,7 @@ fn help() !void { try stdout.print("FILE (デフォルトは現在のディレクトリ) に関する情報を一覧表示します。\n\n", .{}); //try stdout.print("-a . で始まる要素を無視しない\n", .{}); //try stdout.print("-A . および .. を一覧表示しない\n", .{}); - //try stdout.print("-l use a long listing format\n", .{}); + try stdout.print("-l use a long listing format\n", .{}); //try stdout.print("-m -l と併せて使用され、サイズを 1K, 234M, 2Gのような形式で表示する。\n", .{}); //try stdout.print("-r ソート順を反転させる\n", .{}); //try stdout.print("-R 子ディレクトリを再帰的に一覧表示する\n", .{}); @@ -86,6 +87,10 @@ pub fn main() !void { var iter = dir.iterate(); var stdout = io.getStdOut().writer(); + if (isl) { + //try stdout.print("許可\tオーナー\tグループ\t", .{}); + try stdout.print("サイズ\t変更日 (GMT)\t\tファイル名\n", .{}); + } while (try iter.next()) |entry| { if (iss) { @@ -95,6 +100,25 @@ pub fn main() !void { const stat = try file.stat(); const size = stat.size; try stdout.print("{d} {s}\t", .{ size / BLOCK_SIZE, entry.name }); + } else if (isl) { + var file = try fs.cwd().openFile(entry.name, .{}); + defer file.close(); + var stats = try file.stat(); + std.debug.print("stat: {}\n", .{stats}); + var t = stats.mtime; + const unix = toki.nanoToSecond(@intCast(t)); + const dt = toki.unixToDateTime(unix); + + try stdout.print("{d}\t{d}-{s}-{s} {s}:{s}:{s}\t{s}\n", .{ + stats.size, + dt.year, + toki.fmtDigit(@intCast(dt.month)), + toki.fmtDigit(@intCast(dt.day)), + toki.fmtDigit(@intCast(dt.hour)), + toki.fmtDigit(@intCast(dt.minute)), + toki.fmtDigit(@intCast(dt.second)), + entry.name, + }); } else { try stdout.print("{s}\t", .{entry.name}); }