Skip to content

v0.4.0

Choose a tag to compare

@davidesantangelo davidesantangelo released this 04 Apr 11:37
· 84 commits to main since this release

Added

  • Recursive Directory Search: Introduced the -r option to recursively search directories.
    • Automatically skips binary files based on a heuristic check (presence of null bytes).
    • Skips common non-code directories (e.g., .git, node_modules, build, dist, target) and VCS directories.
    • Skips files with common binary, archive, image, audio/video, and document extensions (e.g., .o, .so, .zip, .gz, .jpg, .png, .pdf, .docx).
    • Follows symbolic links to files but not to directories (to prevent loops).
  • Pattern Specification Option (-e): Added the -e PATTERN option to specify the search pattern. This is particularly useful for patterns that start with a hyphen (-).

Changed

  • Regex Flag: The flag to interpret the pattern as a POSIX Extended Regular Expression (ERE) has been changed from -r to -E. The -r flag is now used exclusively for recursive search.
  • Output Format:
    • When searching files or recursively (-r), output for -c (count lines), -co (count matches), and -o (only matching) is now prefixed with the filename (e.g., filename:count, filename:match).
    • Summary output (-d) is now printed to stderr instead of stdout to keep stdout clean for matching lines/counts.
  • Exit Codes: Aligned exit codes with grep standard behavior:
    • 0: One or more matches were found.
    • 1: No matches were found.
    • 2: An error occurred (e.g., file not found, invalid arguments, memory allocation failure, regex compilation error).
  • Command Line Argument Parsing: Reworked argument parsing to correctly handle the new -e, -E, and -r options, differentiate between positional patterns and -e patterns, and validate file/directory targets based on the selected mode.
  • Threading: Clarified in help messages and warnings that multi-threading (-t) is currently ignored and the tool operates single-threaded for accuracy in modes requiring line state or match positions.
  • Search Algorithm Behavior: Explicitly documented and ensured that literal string search algorithms (Boyer-Moore, KMP, Rabin-Karp) find non-overlapping matches.

Fixed

  • Ensured KMP and Rabin-Karp implementations correctly advance past the found match to guarantee non-overlapping results, consistent with Boyer-Moore.
  • Improved handling of edge cases in regex_search, particularly concerning empty strings, report limits, and advancing past zero-length matches.

Internal

  • Refactored code to add helper functions for checking binary files (is_binary_file) and skippable extensions (should_skip_extension).
  • Moved ANSI color code definitions from krep.c to krep.h.