Make the assumption that the string won't wrap 3 or more lines (though unlikely)
I am a bit confused by this. It looked as though "filename" contained a list of string or re's to match. It seems as though the remaining files contain lines of data. I guess what this means is that the string to match could be very long: possibly 3+ lines. Is that correct?
Some ideas that might get you going:
- Could you modify tcgrep to do what you want? It seems to be pretty close.
- Using the "finger scan" is really ineffecient. This is one reason the re engine is nice. Lots of credit goes to Aho. Here is an article
describing the math. It gets complex, but that is why we have the perl re engine and why we have study.
- It seems as though what you need is a special kind of string that looks to the re engine like a string, but reads from STDIN when it needs to and throws out data in the process: a circular buffer. I searched CPAN and could not find such a beast. Maybe this is a good project?
HTH, --traveler