このコミットが含まれているのは:
守矢諏訪子 2023-07-09 06:47:46 +09:00
コミット e8f2095890
4個のファイルの変更91行の追加0行の削除

ファイルの表示

@ -2,5 +2,6 @@
* catを追加
* cpを追加
* lsを追加
* pwdを追加(完了)
* rmを追加(完了)
* touchを追加

ファイルの表示

@ -8,6 +8,7 @@ all:
cd cat && make && mv cat ../bin && rm -rf cat.o && cd ..
cd cp && make && mv cp ../bin && rm -rf cp.o && cd ..
cd ls && make && mv ls ../bin && rm -rf ls.o && cd ..
cd pwd && make && mv pwd ../bin && rm -rf pwd.o && cd ..
cd rm && make && mv rm ../bin && rm -rf rm.o && cd ..
cd touch && make && mv touch ../bin && rm -rf touch.o && cd ..
@ -20,6 +21,7 @@ install: all
chmod 755 ${DESTDIR}${PREFIX}/bin/cat
chmod 755 ${DESTDIR}${PREFIX}/bin/cp
chmod 755 ${DESTDIR}${PREFIX}/bin/ls
chmod 755 ${DESTDIR}${PREFIX}/bin/pwd
chmod 755 ${DESTDIR}${PREFIX}/bin/rm
chmod 755 ${DESTDIR}${PREFIX}/bin/touch
#mkdir -p ${DESTDIR}${MANPREFIX}/man1

13
pwd/Makefile ノーマルファイル
ファイルの表示

@ -0,0 +1,13 @@
NAME=pwd
VERSION := $(shell cat ../Makefile | grep "VERSION=" | sed 's/VERSION=//')
SRC=${NAME}.zig
CC=zig build-exe
RELEASE=ReleaseSmall
all:
${CC} ${SRC} -O ${RELEASE} --name ${NAME}
clean:
rm -f ${NAME} ${NAME}.o
.PHONY: all clean

75
pwd/pwd.zig ノーマルファイル
ファイルの表示

@ -0,0 +1,75 @@
const std = @import("std");
const io = std.io;
const os = std.os;
const fs = std.fs;
const version = "1.0.0";
fn help() !void {
const stdof = io.getStdOut().writer();
var bw = io.bufferedWriter(stdof);
const stdout = bw.writer();
try stdout.print("076 coreutils\n", .{});
try stdout.print("使用法: pwd\n", .{});
try stdout.print("現在のパスを表示する。\n\n", .{});
try stdout.print("-h ヘルプを表示\n", .{});
try stdout.print("-v バージョンを表示\n", .{});
try bw.flush();
}
fn ver() !void {
const stdof = io.getStdOut().writer();
var bw = io.bufferedWriter(stdof);
const stdout = bw.writer();
try stdout.print("pwd (076 coreutils) {s}\n", .{version});
try bw.flush();
}
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const alloc = gpa.allocator();
var option = std.ArrayList(u8).init(alloc);
defer option.deinit();
const args = try std.process.argsAlloc(alloc);
defer std.process.argsFree(alloc, args);
for (args, 0..) |arg, i| {
if (i == 0) continue;
var m: [1]u8 = [_]u8{'-'};
if (std.mem.eql(u8, arg[0..1], m[0..])) {
for (arg, 0..) |a, j| {
if (j == 0) continue;
try option.append(a);
}
}
}
for (option.items) |i| {
if (i == 'h') {
try help();
return;
}
if (i == 'v') {
try ver();
return;
}
}
var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
const cwd = fs.cwd();
const path = try cwd.realpath(".", &buf);
const stdof = io.getStdOut().writer();
var bw = io.bufferedWriter(stdof);
const stdout = bw.writer();
try stdout.print("{s}\n", .{std.mem.trim(u8, path, "\x00")});
try bw.flush();
}