This is a Matlab implementation of the unix patch utility, though
not fully featured. It currently only works on unified diff text
files, ie, the files created by "diff -u old new" and is not POSIX
mypatcher( file_to_be_patched, patch )
patched_text = mypatcher( ... )
[patched_text, info] = mypatcher( ... )
MYPATCHER( file_to_be_patched, patch ) takes a unified diff file
specified by patch and applies it to file_to_be_patched.
The resulting file is output to file_to_be_patched.patched
as well as output to the screen. file_to_be_patched must be
a text file, not binary. mypatcher does not check whether the
surrounding text matches.
patched_text = mypatcher( ... ) puts the changed text in
patched_text instead of displaying and outputting to file
[patched_text, info] = mypatcher( ... ) also includes some info
about the patch file hunks and file_to_be_patched.
mypatcher(..., output_file) uses output_file instead of
file_to_be_patched.patched as the output destination.
file_to_be_patched - Name of the file to be patched. Cannot be a
patch - Name of the patch file to apply. Must be a unified diff
output_file - Name of the file to output to. Will be erased if it
patched_text - A string containing the result of applying the
patch file to the input file.
info - A struct containing the input file as a whole string and
line-by-line in a struct and the hunks of the patch file in a
different struct along with the hunk header information.
Given the files 'file.old' and 'file.new' we can find the updates
%>diff -u file.old file.new > file.patch
We can now run mypatcher to get a patched version of 'file.old'
Wikipedia Diff Article