Hi perl monks,
Currently I need to build tool/script to applying diff but with some rules or customization. I can't just generate diff/patch file and then apply to the source. Actually for now, we do this manually (human intervention). My task now is to make this automatic...and in the end still open visual diff tool for human review. There are 7 C source ( 3 *.c and 4*.h) need to be applied. Not many but it's still hard.

Here's an example if in the ./new/file1 doesnt exist keyword like #ifdef __FOO__ paired with #endif which exist in ./old/file1, then apply that to the file1 in ./merged/file1. Or like #include<XXX> in ./old/file1 that also must be applied and so on.
Another example, there's 1 file contains ridiculous amount of hexa bytecodes which differ here and there between the ./new/file1 and ./old/file1. The rules for this is don't apply any bytecode changes ,IOW, keep it that way. And then one other rule is if in the new/file1 contain new function prototypes which old/file1 don't, keep it that way. I hope you guys now what I mean.
There are more rules actually, not that many, some are just base on obvious keyword, some are more base on pattern and then one special case is must input keyword in the middle. Example:

one line in ./new/file1: abcdefghjiklm 0x1356 one line in ./old/file1: abcdefghijklm BULL((0x1150) one line in new copy of ./merged/file1 must be: abcdefghijklm BULL(0x1356)
Now, imagine the above example exist hundreds time,sparsely. But I think ,maybe, I know the pattern of the BULL appearances in old/file1 cause there are same remark/comment in file1 for each section which is very useful I guess to make this automatic. Maybe wrong though. This latter example is tedious if you do it manually. But Thank God this only happen in one file.

Anyway, I think that's all for my explanation. Hope the monks get this clear. This task is challenging enough for me that now I ran out of idea. If perl can't do it, I dont know any tool can do it...well,except human brain.

My current half-idea is , put the rules of keyword/pattern as an array or maybe hash. and then what ?
Also my previous idea was generate unified diff patch file. And then edit the patch file, output to 2nd customized patch file. Apply the 2nd patch file. In short,I have had trouble editing diff file not to mention 'Patch' complain regarding my edited patch file. And other problem is if in 1 chunk from diff file contains part that need to be applied and need not applied.
BTW,currently my tools are activeperl, Text::Diff pm, and gnuwin32 patch. I hope 'patch' is the only external util to minimize dependency/app requirement.

So, do you guys have any applicable idea? Or is this attempt-to-automatize thing impossible to be done by machine ? Thanks very much in advance


In reply to Applying diff partially using perl by mhd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.