This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
KillaVanilla's profile picture

Diff & Patch

Started by KillaVanilla, 06 September 2013 - 09:31 PM
KillaVanilla #1
Posted 06 September 2013 - 11:31 PM
Hello all.

I was bored just now, and decided to revisit an old problem that had stumped me before: the longest common subsequence problem, used in programs like in the "real" diff utility.
After doing a bit more reading on the LCS problem, I decided that I would try to implement it in CC. A few hours later, I created this.

It's a simple implementation of the diff and patch utilities used in Unix-likes. It's really simple to use:

diff old_file new_file patch_file


patch copy_of_old_file patch_file

The first command will create a diff of old_file and new_file, outputting the diff (and therefore patch) to patch_file.
The second command will patch copy_of_old_file to new_file, writing the "new" version of copy_of_old_file to copy_of_old_file.out.

It's only designed to work with text files.

It should work, though I can't make any promises; it's another of my "I'm-bored-so-rush-this" programs.

Anyways, links:
Diff: Pastebin (Code: CbKFJdaU)
Patch: Pastebin (Code: V1N1bRL2)
RazeLion #2
Posted 06 September 2013 - 11:53 PM
Screenshots? :)/>
rhyleymaster #3
Posted 07 September 2013 - 12:11 AM
It's a great idea although some people may not find it of use in CC.
Mitchfizz05 #4
Posted 07 September 2013 - 04:48 AM
I'm confused. :(/>
Head goes boom. How sad.
KillaVanilla #5
Posted 07 September 2013 - 09:57 AM
It's a great idea although some people may not find it of use in CC.
Yeah, most of my stuff is mainly written to show that it can be written.

I'm confused. :(/>
Head goes boom. How sad.
The diff utility determines the differences between two files and writes it to a file that can be read by patch.

For example:
Say you have a program, and you just wrote a newer version of it. You can take the old and new versions of the program and generate a patch file using diff.
Then, if you have any other copies of the old version of the program (say on another computer), you can use the patch program to update every copy to the new version using the patch file from earlier.
Mitchfizz05 #6
Posted 08 September 2013 - 08:03 AM
It's a great idea although some people may not find it of use in CC.
Yeah, most of my stuff is mainly written to show that it can be written.

I'm confused. :(/>
Head goes boom. How sad.
The diff utility determines the differences between two files and writes it to a file that can be read by patch.

For example:
Say you have a program, and you just wrote a newer version of it. You can take the old and new versions of the program and generate a patch file using diff.
Then, if you have any other copies of the old version of the program (say on another computer), you can use the patch program to update every copy to the new version using the patch file from earlier.
That is an awesome great idea!
Good job!
BigTwisty #7
Posted 12 September 2013 - 12:42 PM
Is this kindof like a CC version of WinMerge then?
electrodude512 #8
Posted 12 September 2013 - 05:02 PM
Is it compatible with Unix diff and patch?
KillaVanilla #9
Posted 13 September 2013 - 05:15 PM
Is it compatible with Unix diff and patch?
Probably Definitely not.

Is this kindof like a CC version of WinMerge then?
WinMerge appears to be a Windows version of *nix diff with a GUI.
So, yeah.