File Exchange

image thumbnail

MyPatcher

version 1.0 (3.02 KB) by

Function to patch files a la the UNIX patch utility from unified diff files using pure Matlab.

0 Downloads

Updated

View License

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
compliant.

SYNTAX:
mypatcher( file_to_be_patched, patch )
patched_text = mypatcher( ... )
[patched_text, info] = mypatcher( ... )
mypatcher(..., output_file)

DESCRIPTION:
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.

INPUTS:
file_to_be_patched - Name of the file to be patched. Cannot be a
binary file
patch - Name of the patch file to apply. Must be a unified diff
file.
output_file - Name of the file to output to. Will be erased if it
already exists.
OUTPUTS:
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.
EXAMPLES:
Given the files 'file.old' and 'file.new' we can find the updates
using
%>diff -u file.old file.new > file.patch
We can now run mypatcher to get a patched version of 'file.old'
like so:
mypatcher('file.old','file.patch')
SEE ALSO:
Wikipedia Diff Article

Comments and Ratings (0)

MATLAB Release
MATLAB 7.13 (R2011b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video