MyPatcher

Function to patch files a la the UNIX patch utility from unified diff files using pure Matlab.
233 Downloads
Updated 3 May 2013

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

Cite As

Michael Ryan (2024). MyPatcher (https://www.mathworks.com/matlabcentral/fileexchange/41622-mypatcher), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on File Operations in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0