Re: Question about 'patching' source code.

Niklas Holsti <[email protected]>
Newsgroups gmane.comp.gnu.mingw.user
Organization Tidorum Ltd
Message-ID <[email protected]>
On 19-10-12 03:39 , David Wall wrote:
> I regularly 'build' GnuCOBOL compiler from source code - however it is
> supplied in 'tar' format.
> I use 'tar' to unpack it and then I need to make changes to certain
> files all the time.
>
> Is there any program in Mingw 6.3.0 that I can utilise to do these
> patches for me.

The "patch" and "diff" tools are designed for this.

> I installed msys-patch and checked thru the documentation - but it
> processes a 'diff' file and
> that confused me no end. Maybe I'll have to investigate how to produce a
> 'diff' file.

Yes.

This is the process: first,

1. Make a copy of all the original files from the "tar".

2. Edit the copy manually, applying the changes you need (which is what 
you have done so far for all "tar" versions, so you could use the last 
version of your edited files instead).

3. Run "diff" to compare the original file set with the manually edited 
file set. Store the resulting diff output as a "diff file". This file a 
record of the changes that you made manually; it identifies the files 
that were changed, the places in the files that were changed, and the 
change (old text => new text).

When, later, you get a new "tar", you run "patch" on the new files using 
the "diff file" that you got from step 3 above. "Patch" then reapplies 
the same changes you did on the original "tar" file set and which were 
recorded in the "diff file".

"Patch" tolerates a certain amount of evolution in the "tar" files from 
one version to the next, but if there is too much of that -- for 
example, if a function that you changed, as shown in the "diff" file, no 
longer exists in the new "tar" files or has been moved somewhere far 
away -- "patch" reports an error and then you have to consider what to 
do and perhaps edit something manually again. If you have to do that, 
you can then make, with "diff", a new "diff file" that reflects this 
evolution of the "tar" files, and the new "diff file" should work better 
when the next new "tar" arrives.

> What I'd like to do is tell a patch program to:
>
> 1. Find this file     2. Find this text in the file    3. Replace found
> text with new text.

That is exactly what the patch+diff combination can do.

HTH,

Niklas Holsti

_______________________________________________
MinGW-Users mailing list
[email protected]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.osdn.me/mailman/listinfo/mingw-users
Also: mailto:[email protected]?subject=unsubscribe
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.