I managed to modify a sed script (blockrep.sed)...
... intended to replace all instances of a multi-line text segment (a C program function) and replace it by a replacement text (a "vastly" modified C program function) ...
... and made that work. All details and final results are documented here [
https://stackoverflow.com/questions/75305074/trying-to-get-generic-sed-multi-line-pattern-match-and-substitution-script-to-wo/75331049?noredirect=1#comment132942453_75331049 ].
As noted in one of my comments ...
... As long as all source code files are standardized, and elements were copy+pasted, the above solution will cover everything.
Now, I would like to generalize that beyond matching of cookie-cutter templates and add logic to
- strip leading whitespaces,
- trailing whitespaces, and
- map multiple-whitespaces to a single-space
... for both the match pattern,
... and the edited file "evaluation buffer",
to allow for random format of manually entered copies, to ensure no cases are overlooked.
Thinking about how to achieve that revamping of the embedded ... blockrep.sed ... script, I visualized creating a duplicate of the input buffer, which would match the sliding-window, and apply all massaging to that second copy and use that for comparison with a similarly duplicated and massaged copy of the text segment that is trying to be located.
Then, upon locating and triggering that match condition, the non-massaged text in the file being edited would be replaced by the text segment specified in ... ${fileReplPat} ... which was mapped in the transformation specification file ... findrep.txt .
Not truly understanding if it is possible to have 4 (or 5) buffers open at the same time, with 2 pairs of "synchronized" buffers (excuse my misuse of that description), I was thinking that those maybe associated each with its own "marker" (or numbered register) ...
... and do the line-by line copy+swap/strip/compare/adjust/swap-back/adjust/reposition/repeat cycle ...
Is such a thing possible?
I would really like guidance at a high-level (abstract) so I have a concrete feel for the "components" and their relationships before trying to tackle the actual coding.
Does that make sense ?
Is that even possible ?
Your suggestions and ideas would be really appreciated.
Thank you, everyone.