menios icon indicating copy to clipboard operation
menios copied to clipboard

Port grep utility to meniOS

Open pbalduino opened this issue 3 months ago • 0 comments

Description

Port the grep utility to meniOS to enable pattern matching and text searching in files from the shell.

Requirements

Implement a basic grep utility with essential functionality:

  • grep PATTERN FILE - Search for pattern in file
  • grep PATTERN - Search for pattern in stdin (for use in pipelines)
  • Support for basic regular expressions or simple string matching
  • Exit status: 0 if match found, 1 if no match, 2 on error
  • Basic flags (optional):
    • -i - Case-insensitive matching
    • -v - Invert match (show non-matching lines)
    • -n - Show line numbers
    • -c - Count matching lines

Implementation Details

The utility should:

  • Work with the existing file I/O syscalls (open, read, close)
  • Handle stdin for pipeline support (e.g., cat file.txt | grep foo)
  • Use the userland libc for string operations
  • Follow POSIX-like conventions for grep behavior
  • Handle edge cases (empty files, binary files, no matches)

Usage Examples

$ grep "error" /var/log/system.log
error: Failed to mount device

$ cat file.txt | grep "TODO"
// TODO: Fix this function

$ grep -n "main" program.c
42:int main(int argc, char **argv) {

Dependencies

  • #193 - Minimal userland libc ✅ (COMPLETE)
  • #60 - Filesystem syscalls ✅ (COMPLETE)
  • #102 - Pipes implementation ✅ (COMPLETE - for pipeline support)

Acceptance Criteria

  • [ ] grep PATTERN FILE searches file for pattern
  • [ ] grep PATTERN reads from stdin for pipeline usage
  • [ ] Proper exit status codes (0/1/2)
  • [ ] Basic pattern matching works (literal strings at minimum)
  • [ ] Works in pipelines with other utilities
  • [ ] Test coverage for grep functionality
  • [ ] Documentation/man page entry

Estimated Effort

2-3 days

Priority

Medium - Useful utility for text processing and debugging

Milestone

Consider for future utility expansion after Mosh milestone completion

pbalduino avatar Oct 09 '25 16:10 pbalduino