diff --git a/README.md b/README.md index 5e838c2..7df0667 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,18 @@ -A `wc` like program written by `C++` but built by `Zig`. +# Coreutils Implementation + +A project to implement GNU coreutils utilities in `C++` and `Zig`. This is an ongoing effort to recreate the essential Unix/Linux command-line tools. + +## Implemented Utilities + +- `wc`: Word, line, and byte counting utility + +## Planned Utilities + +The project aims to implement all core utilities, including but not limited to: +- File Management: `ls`, `cp`, `mv`, `rm`, `mkdir`, `cat`, etc. +- Text Processing: `head`, `tail`, `sort`, `uniq`, etc. +- System Information: `pwd`, `whoami`, `uname`, etc. +- And many more... ## Installation @@ -16,11 +30,11 @@ cd wc zig build ``` -The executable will be available at `zig-out/bin/wc`. +The executables will be available in `zig-out/bin/`. ## Usage -### Examples +### wc Examples Count lines, words, and characters in a file: ```bash @@ -37,6 +51,14 @@ Count words from standard input: cat file.txt | wc -w ``` +## Contributing + +Contributions are welcome! Feel free to: +- Implement new utilities +- Improve existing implementations +- Report bugs +- Suggest enhancements + ## License Licensed under Apache-2.0 license ([LICENSE](LICENSE) or http://opensource.org/licenses/Apache-2.0) \ No newline at end of file diff --git a/build.zig b/build.zig index c9b307f..92c337b 100644 --- a/build.zig +++ b/build.zig @@ -1,47 +1,47 @@ const std = @import("std"); const zcc = @import("compile_commands"); -const executable_name = "wc"; - pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); var targets = std.ArrayList(*std.Build.Step.Compile).init(b.allocator); + defer targets.deinit(); - const exe = b.addExecutable(.{ - .name = executable_name, + const wc_exe = b.addExecutable(.{ + .name = "wc", .target = target, .optimize = optimize, }); - targets.append(exe) catch @panic("OOM"); + targets.append(wc_exe) catch @panic("OOM"); const cpp_sources = [_][]const u8{ - "src/main.cpp", - "src/wc.cpp", - "src/options.cpp", - "src/params.cpp", + "src/wc/main.cpp", + "src/wc/wc.cpp", + "src/wc/options.cpp", + "src/wc/params.cpp", }; for (cpp_sources) |source| { - exe.addCSourceFile(.{ + wc_exe.addCSourceFile(.{ .file = b.path(source), .flags = &[_][]const u8{"-std=c++20"}, }); } - exe.linkLibCpp(); - exe.addIncludePath(b.path("src")); + wc_exe.linkLibCpp(); + wc_exe.addIncludePath(b.path("src/wc")); + + b.installArtifact(wc_exe); - b.installArtifact(exe); + const run_step = b.step("run-wc", "Run the wc app"); - const run_cmd = b.addRunArtifact(exe); + const run_cmd = b.addRunArtifact(wc_exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); } - const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); zcc.createStep(b, "cdb", targets.toOwnedSlice() catch @panic("OOM")); } diff --git a/src/main.cpp b/src/wc/main.cpp similarity index 100% rename from src/main.cpp rename to src/wc/main.cpp diff --git a/src/options.cpp b/src/wc/options.cpp similarity index 100% rename from src/options.cpp rename to src/wc/options.cpp diff --git a/src/options.hpp b/src/wc/options.hpp similarity index 100% rename from src/options.hpp rename to src/wc/options.hpp diff --git a/src/params.cpp b/src/wc/params.cpp similarity index 100% rename from src/params.cpp rename to src/wc/params.cpp diff --git a/src/params.hpp b/src/wc/params.hpp similarity index 100% rename from src/params.hpp rename to src/wc/params.hpp diff --git a/src/wc.cpp b/src/wc/wc.cpp similarity index 100% rename from src/wc.cpp rename to src/wc/wc.cpp diff --git a/src/wc.hpp b/src/wc/wc.hpp similarity index 100% rename from src/wc.hpp rename to src/wc/wc.hpp