Le 2015-04-23 19:29, Laurent Bloch a écrit :

And what about mmap + pregexp-match ?

Here is my try on it. Besides the ugly copying operations, it seems to me that the multiline option doesn't make what I was waiting for: finding a pattern across a newline.

Cheers,

--
Laurent Bloch - http://www.laurentbloch.org/ - [email protected]
(module mmap-pattern-search
   (main file-parse))

(define (file-parse args)
   (let ((the-sequence (open-mmap (cadr args) read: #t write: #t))
         (pattern (caddr args)))
      (analyse the-sequence pattern)
      (close-mmap the-sequence)
       ))

(define (analyse sequence pattern)
   (let ((len (mmap-length sequence))
         (regexp (pregexp pattern 'MULTILINE)))
      (let loop ((start::belong (make-elong 0)))
         (let* ((sequence-rem (mmap-substring sequence start len))
                (result (pregexp-match-positions regexp sequence-rem)))
            (if result
                (begin
                   (print "From " (+ start (caar result)) " to " (+ start (cdar 
result)))
                   (loop (+ start (cdar result)))) ) ) )))

Attachment: raw-sequence-file.txt
Description: Binary data

Reply via email to