Project 3: A cat Clone

A command-line utility, my_cat, that reads the contents of a specified file and prints them to standard output.

Quick Reference

Attribute Value
Primary Language C++
Alternative Languages N/A
Difficulty Level 2: Intermediate
Time Estimate A few hours
Knowledge Area File I/O / Command-Line Tools
Tooling LibCore, LibMain
Prerequisites Project 1, basic C++.

What You Will Build

A command-line utility, my_cat, that reads the contents of a specified file and prints them to standard output.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Parsing command-line arguments → maps to using Core::ArgsParser
  • Opening and reading a file → maps to Core::File and its APIs
  • Handling I/O errors → maps to using the ErrorOr<T> pattern prevalent in SerenityOS
  • Writing to standard output → maps to basic console I/O

Key Concepts

  • Error Handling: The ErrorOr<T> pattern is explained in SerenityOS’s Documentation/CodingStyle.md.
  • File I/O: Explore Userland/Libraries/LibCore/File.h.
  • Argument Parsing: Explore Userland/Libraries/LibCore/ArgsParser.h.

Real-World Outcome

Deliver a working demo with observable output that proves the feature is correct.


Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: LEARN_SERENITYOS_DEEP_DIVE.md
  • “The C++ Programming Language” by Bjarne Stroustrup (for modern C++ idioms)