cl-grep

Simple implementation of grep
Log | Files | Refs

commit 70a7469d7ad3f2a9b05f0de06f2d1682609ba737
parent 7fce8fc3c0344e462ad713a803b2040f448318d1
Author: ChanderG <[email protected]>
Date:   Wed,  3 Dec 2025 19:15:55 +0530

pull out formatting func; add grep like alternative

for easy parity checks wrt count
small examples show more or less parity with grep/rg

Diffstat:
Mgrep.lisp | 18+++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/grep.lisp b/grep.lisp @@ -11,6 +11,20 @@ (defstruct file-result name entries) +;; rg like combined format +(defun format-file-result (fr stream) + (write-string + (format nil + "~a: ~%~{~A~%~}~%" + (file-result-name fr) + (file-result-entries fr)) + stream)) + +;; ;; alternative grep like format to easily test parity +;; (defun format-file-result (fr stream) +;; (loop for e in (file-result-entries fr) do +;; (write-string (format nil "~a: ~a~%" (file-result-name fr) e) stream))) + (defun grep-file (file match-idx) (lo "Grepping file: ~a" file) (handler-case @@ -46,9 +60,7 @@ ;; flush out remaining stuff (princ (get-output-stream-string bufstream)) (return)) - (let ((name (file-result-name task)) - (results (file-result-entries task))) - (write-string (format nil "~a: ~%~{~A~%~}~%" name results) bufstream)) + (format-file-result task bufstream) (incf count) ;; buffer and print out (when (eq count 10)