Patch (Stringlist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (Syntax diagram and tags)
Line 1: Line 1:
{{Template:Stringlist:Patch subtitle}}
{{Template:Stringlist:Patch subtitle}}


This method uses Unix-style <tt>.diff</tt> output to update text lines that are stored in a <var>Stringlist</var>. Typically, a <tt>.diff</tt> utility creates a report (a "patch file") of the differences between two "files," a base file and an updated version of the base file: that is, '''patch = diff(base, updated)'''. Depending on which diff utility and command format that creates it, a patch may report the differences between the two files using a line orientation or a character orientation:
This method uses Unix-style <var class="term">diff</var> output to update text lines that are stored in a <var>Stringlist</var>.
<ul>
 
<li>In the line orientation, the diff treats each file as a set of lines, and it reports whole-line differences, specifying changes by line number.
Typically, a <var class="term">diff</var> utility creates a report (a "patch file") of the differences between two "files," a base file and an updated version of the base file: that is, <var class="example">patch = diff(base, updated)</var>. Depending on which diff utility and command format that creates it, a patch may report the differences between the two files using a line orientation or a character orientation:
<li>In the character orientation, the diff treats each file as a single string of characters, and it reports character differences, specifying changes by character position.
<ul><li>In the line orientation, the <var class="term">diff</var> treats each file as a set of lines, and it reports whole-line differences, specifying changes by line number.
</ul>
<li>In the character orientation, the <var class="term">diff</var> treats each file as a single string of characters, and it reports character differences, specifying changes by character position.</ul>
 
<var>Patch</var> supports only line-oriented differences. For working with character-oriented <var class="term">diff</var> output, use the <var>[[PatchString (Stringlist function)|PatchString]]</var>.
 
<var>Patch</var> applies a given patch file (converted to a <var>Stringlist</var>) to a base file (also a <var>Stringlist</var>), and it returns an output <var>Stringlist</var> that is the base file updated by the differences contained in the patch file. Patch has the same functionality as the <var>[[PatchLines (Stringlist function)|PatchLines]]</var>, but its syntax is slightly different: it reverses the method object and first argument of <var>[[PatchLines (Stringlist function)|PatchLines]]</var> (and <var>[[PatchString (Stringlist function)|PatchString]]</var>). 
 
<b>Note:</b>The patch file you use is assumed to be in line-oriented <var class="term">diff</var> output format.  The reference source used for this format is the GNU diff manual, see [http://www.gnu.org/software/diffutils/manual/#Top Comparing and Merging Files].
 
Only output from a normal <var class="term">diff</var> command or from a <var class="term">diff [-u | U <i>n</i>]</var> command is supported.


The <var>Patch</var> method supports only a line-oriented patch. For working with character-oriented <tt>.diff</tt> output, use the [[PatchString (Stringlist function)]]. The Patch method applies a given patch file (converted to a Stringlist) to a base file (also a Stringlist), and it returns a Stringlist that is the base file updated by the differences contained in the patch file. Patch has the same functionality as the [[PatchLines (Stringlist function)]], but its syntax is slightly different: it reverses the method object and first argument of PatchLines (and PatchString).  ''The patch file you use is assumed to be in line-oriented <tt>.diff</tt> output format.''  The reference source used for this format is the GNU diff manual, '''Comparing and Merging Files''' (see http://www.gnu.org/software/diffutils/manual/html_mono/diff.html). Only output from a normal <tt>.diff</tt> command or from a <tt>. diff [-u | U <i>n</i>]</tt> command is supported. The <var>Patch</var> method is available as of <var class=product>Sirius Mods</var> Version 7.1.
<var>Patch</var> is available as of <var class="product">Sirius Mods</var> Version 7.1.


==Syntax==
==Syntax==
Line 13: Line 21:
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>updSL</th>
<tr><th>updList</th>
<td>A <var>Stringlist</var> object that reproduces the original updated file, that is, '''%sl''' updated by the '''patchStrL''' updates. </td></tr>
<td>A <var>Stringlist</var> object that reproduces the original updated file, that is, <var class="term">sl</var> updated by the <var class="term">patchList</var> updates. </td></tr>
<tr><th>baseSL</th>
<tr><th>sl</th>
<td>A <var>Stringlist</var> object that contains the original base file, each line stored as a '''baseSL''' item. </td></tr>
<td>A <var>Stringlist</var> object that contains the original base file, each line stored as a <var class="term">sl</var> item. </td></tr>
<tr><th>patchSL</th>
<tr><th>patchList</th>
<td>A <var>Stringlist</var> object that contains the patch file (one line per '''patchSL''' item). </td></tr>
<td>A <var>Stringlist</var> object that contains the patch file (one line per <var class="term">patchList</var> item). </td></tr>
<tr><th>Options='ErrRet'</th>
<tr><th>Options</th>
<td>The optional Options argument (name required) is the string value <tt>.ErrRet</tt>, which may be specified in uppercase or lowercase. If you specify <tt>.Options='ErrRet'</tt>, <var>Patch</var> method errors return a null '''updSL''' <var>Stringlist</var> and no error message instead of canceling the request. If you do not specify <tt>.Options='ErrRet'</tt> and a method error occurs, you receive an error message and the run is canceled.</td></tr>
<td>The optional <var class="term">Options</var> argument (name required) is the string value <var class="term">'ErrRet'</var>, which may be specified in uppercase or lowercase. If you specify <var class="term">Options='ErrRet'</var>, <var>Patch</var> method errors return a null <var class="term">updList</var> <var>Stringlist</var> and no error message instead of canceling the request. If you do not specify <var class="term">Options='ErrRet'</var> and a method error occurs, you will receive an error message and the request will be canceled.</td></tr>
</table>
</table>


==Usage notes==
==Usage notes==
<ul>
<ul><li>The <var>Stringlist</var> returned by the <var>Patch</var> method, <var class="term">updList</var>, will be a Null object if <var>Patch</var> encounters a non-canceling error.
<li>The <var>Stringlist</var> returned by the <var>Patch</var> method, '''updSL''', is a Null object if <var>Patch</var> encounters a non-canceling error.
<li><var>Patch</var> supports <var class="term">normal</var> and <var class="term">unified</var> <var class="term">diff</var> output formats only. A supported unified-format patch may either be:
<li>The <var>Patch</var> method supports '''normal''' and '''unified''' <tt>.diff</tt> output formats only. A supported unified-format patch may either be:
<ul><li>Output from <var class="term">diff -u</var>, which includes the three lines of text immediately before and after a change to the base.
<ul>
<li>Output from <var class="term">diff -U <i>n</i></var>, where <i>n</i> is 0 or greater, which includes the number of lines of surrounding text you specify with <i>n</i>.
<li>Output from <tt>.diff</tt> <tt>.-u</tt>, which includes the three lines of text immediately before and after a change to the base.
<li>Output from <tt>.diff</tt> <tt>.-U</tt> <tt>.<i>n</i></tt>, where <i>n</i> is 0 or greater, which includes the number of lines of surrounding text you specify with <i>n</i>.
</ul>
</ul>
A patch file in '''context''' format (output from <tt>.diff</tt> <tt>.-c</tt> or from <tt>.diff</tt> <tt>.-C</tt> <tt>.<i>n</i></tt></i> is ''not'' supported. If specified, a Null <var>Stringlist</var> object is returned or the run is canceled. A context-format <tt>.diff</tt> also may include the text immediately before and after a change.
A patch file in <b>context</b> format (output from <var class="term">diff -c</var> or from <var class="term">diff -C <i>n</i></var>) is <b><i>not</i></b> supported. If specified, a Null <var>Stringlist</var> object is returned or the request is canceled. A context-format <var class="term">diff</var> also may include the text immediately before and after a change.
<li>The representation of the patch file data in <var>Stringlist</var> form should match the original patch exactly. For example, it is critical to preserve leading and trailing blanks.
<li>The representation of the patch file data in <var>Stringlist</var> form should match the original patch exactly. For example, it is critical to preserve leading and trailing blanks.
<li>If the patch contains an '''incomplete line''' warning like " \ No newline at end of file," which indicates a missing line-end character, the <var>Patch</var> method ignores it.
<li>If the patch contains an <b><i>incomplete line</i></b> warning like " \ No newline at end of file," which indicates a missing line-end character, <var>Patch</var> will ignore it.
</ul>
</ul>


==Examples==
==Examples==
In the following example, a patch file (procedure BASEDIFF) is applied to a base file (procedure BASEFILE) to reproduce the updated version of the base file. BASEDIFF contains the diff output (normal), which was sent to ''Model 204'' after comparing the PC files basefile.txt and basefileUpd.txt. The [[AppendOpenProcedure (Stringlist function)]] converts the procedure text to a <var>Stringlist</var>.
In the following example, a patch file (procedure BASEDIFF) is applied to a base file (procedure BASEFILE) to reproduce the updated version of the base file. BASEDIFF contains the diff output (normal), which was sent to <var class="product">Model 204</var> after comparing the PC files basefile.txt and basefileUpd.txt. The <var>[[AppendOpenProcedure (Stringlist function)|AppendOpenProcedire]]</var> converts the procedure text to <var>Stringlists</var>.


<p class="code">Begin
<p class="code">Begin
Line 47: Line 53:
%ptch = new
%ptch = new


* move base file into stringlist
<nowiki>*</nowiki> move base file into stringlist
%rc = $procopn('BASEFILE', 'JALPROC')
%rc = $procopn('BASEFILE', 'JALPROC')
%base:appendOpenProcedure
%base:appendOpenProcedure
Line 53: Line 59:
%base:Print
%base:Print


* move patch file into stringlist
<nowiki>*</nowiki> move patch file into stringlist
%rc = $procopn('BASEDIFF', 'JALPROC')
%rc = $procopn('BASEDIFF', 'JALPROC')
%ptch:appendOpenProcedure
%ptch:appendOpenProcedure
Line 59: Line 65:
%ptch:Print
%ptch:Print


* produce updated file from patch
<nowiki>*</nowiki> produce updated file from patch
%upd = %base:<var>Patch</var>(%ptch)
%upd = %base:Patch(%ptch)
Print '****************Here is updated base:***************'
Print '****************Here is updated base:***************'
%upd:Print
%upd:Print
Line 86: Line 92:
WITNESS: Yes, it is possible that he could have been alive
WITNESS: Yes, it is possible that he could have been alive
and practicing law.
and practicing law.
****************Here is patch:***************
<nowiki>****************Here is patch:***************</nowiki>
1,16c1,9
1,16c1,9
< ATTORNEY: Doctor, before you performed the autopsy,< did you check for a pulse?< WITNESS: No.< ATTORNEY: Did you check for blood pressure?< WITNESS: No.< ATTORNEY: Did you check for breathing?< WITNESS: No.< ATTORNEY: So, then it is possible that the patient was alive< when you began the autopsy?< WITNESS: No.< ATTORNEY: How can you be so sure, Doctor?< WITNESS: Because his brain was sitting on my desk in a jar.< ATTORNEY: I see, but could the patient have still been< alive, nevertheless?< WITNESS: Yes, it is possible that he could have been alive< and practicing law.---
< ATTORNEY: Doctor, before you performed the autopsy,
< did you check for a pulse?
< WITNESS: No.
< ATTORNEY: Did you check for blood pressure?
< WITNESS: No.
< ATTORNEY: Did you check for breathing?
< WITNESS: No.
< ATTORNEY: So, then it is possible that the patient was alive
< when you began the autopsy?
< WITNESS: No.
< ATTORNEY: How can you be so sure, Doctor?
< WITNESS: Because his brain was sitting on my desk in a jar.
< ATTORNEY: I see, but could the patient have still been
< alive, nevertheless?
< WITNESS: Yes, it is possible that he could have been alive
< and practicing law.
---
> ATTORNEY: Is it possible that the patient was alive
> ATTORNEY: Is it possible that the patient was alive
> when you began the autopsy?
> when you began the autopsy?
Line 98: Line 120:
> WITNESS: Yes. It is possible that he could have been alive
> WITNESS: Yes. It is possible that he could have been alive
> and practicing law.
> and practicing law.
****************Here is updated base:***************
<nowiki>****************Here is updated base:***************</nowiki>
ATTORNEY: Is it possible that the patient was alive
ATTORNEY: Is it possible that the patient was alive
when you began the autopsy?
when you began the autopsy?
Line 109: Line 131:
and practicing law.
and practicing law.
</p>
</p>


==See also==
==See also==
{{Template:Stringlist:Patch footer}}
{{Template:Stringlist:Patch footer}}

Revision as of 23:47, 26 January 2011

Update base Stringlist with patch Stringlist (Stringlist class)


This method uses Unix-style diff output to update text lines that are stored in a Stringlist.

Typically, a diff utility creates a report (a "patch file") of the differences between two "files," a base file and an updated version of the base file: that is, patch = diff(base, updated). Depending on which diff utility and command format that creates it, a patch may report the differences between the two files using a line orientation or a character orientation:

  • In the line orientation, the diff treats each file as a set of lines, and it reports whole-line differences, specifying changes by line number.
  • In the character orientation, the diff treats each file as a single string of characters, and it reports character differences, specifying changes by character position.

Patch supports only line-oriented differences. For working with character-oriented diff output, use the PatchString.

Patch applies a given patch file (converted to a Stringlist) to a base file (also a Stringlist), and it returns an output Stringlist that is the base file updated by the differences contained in the patch file. Patch has the same functionality as the PatchLines, but its syntax is slightly different: it reverses the method object and first argument of PatchLines (and PatchString).

Note:The patch file you use is assumed to be in line-oriented diff output format. The reference source used for this format is the GNU diff manual, see Comparing and Merging Files.

Only output from a normal diff command or from a diff [-u | U n] command is supported.

Patch is available as of Sirius Mods Version 7.1.

Syntax

%updList = sl:Patch( patchList, [Options= string])

Syntax terms

updList A Stringlist object that reproduces the original updated file, that is, sl updated by the patchList updates.
sl A Stringlist object that contains the original base file, each line stored as a sl item.
patchList A Stringlist object that contains the patch file (one line per patchList item).
Options The optional Options argument (name required) is the string value 'ErrRet', which may be specified in uppercase or lowercase. If you specify Options='ErrRet', Patch method errors return a null updList Stringlist and no error message instead of canceling the request. If you do not specify Options='ErrRet' and a method error occurs, you will receive an error message and the request will be canceled.

Usage notes

  • The Stringlist returned by the Patch method, updList, will be a Null object if Patch encounters a non-canceling error.
  • Patch supports normal and unified diff output formats only. A supported unified-format patch may either be:
    • Output from diff -u, which includes the three lines of text immediately before and after a change to the base.
    • Output from diff -U n, where n is 0 or greater, which includes the number of lines of surrounding text you specify with n.

    A patch file in context format (output from diff -c or from diff -C n) is not supported. If specified, a Null Stringlist object is returned or the request is canceled. A context-format diff also may include the text immediately before and after a change.

  • The representation of the patch file data in Stringlist form should match the original patch exactly. For example, it is critical to preserve leading and trailing blanks.
  • If the patch contains an incomplete line warning like " \ No newline at end of file," which indicates a missing line-end character, Patch will ignore it.

Examples

In the following example, a patch file (procedure BASEDIFF) is applied to a base file (procedure BASEFILE) to reproduce the updated version of the base file. BASEDIFF contains the diff output (normal), which was sent to Model 204 after comparing the PC files basefile.txt and basefileUpd.txt. The AppendOpenProcedire converts the procedure text to Stringlists.

Begin %base is object stringList %ptch is object stringList %upd is object stringList %rc is float %base = new %ptch = new * move base file into stringlist %rc = $procopn('BASEFILE', 'JALPROC') %base:appendOpenProcedure Print '***************Here is base:***************' %base:Print * move patch file into stringlist %rc = $procopn('BASEDIFF', 'JALPROC') %ptch:appendOpenProcedure Print '****************Here is patch:***************' %ptch:Print * produce updated file from patch %upd = %base:Patch(%ptch) Print '****************Here is updated base:***************' %upd:Print End

The program results show the updated version of the base file, preceded by a display of the base file and the patch file:

***************Here is base:*************** ATTORNEY: Doctor, before you performed the autopsy, did you check for a pulse? WITNESS: No. ATTORNEY: Did you check for blood pressure? WITNESS: No. ATTORNEY: Did you check for breathing? WITNESS: No. ATTORNEY: So, then it is possible that the patient was alive when you began the autopsy? WITNESS: No. ATTORNEY: How can you be so sure, Doctor? WITNESS: Because his brain was sitting on my desk in a jar. ATTORNEY: I see, but could the patient have still been alive, nevertheless? WITNESS: Yes, it is possible that he could have been alive and practicing law. ****************Here is patch:*************** 1,16c1,9 < ATTORNEY: Doctor, before you performed the autopsy, < did you check for a pulse? < WITNESS: No. < ATTORNEY: Did you check for blood pressure? < WITNESS: No. < ATTORNEY: Did you check for breathing? < WITNESS: No. < ATTORNEY: So, then it is possible that the patient was alive < when you began the autopsy? < WITNESS: No. < ATTORNEY: How can you be so sure, Doctor? < WITNESS: Because his brain was sitting on my desk in a jar. < ATTORNEY: I see, but could the patient have still been < alive, nevertheless? < WITNESS: Yes, it is possible that he could have been alive < and practicing law. --- > ATTORNEY: Is it possible that the patient was alive > when you began the autopsy? > WITNESS: No. > ATTORNEY: How can you be so sure, Doctor? > WITNESS: Because his brain was sitting in a jar on my desk. > ATTORNEY: I see. But could the patient have still been > alive, nevertheless? > WITNESS: Yes. It is possible that he could have been alive > and practicing law. ****************Here is updated base:*************** ATTORNEY: Is it possible that the patient was alive when you began the autopsy? WITNESS: No. ATTORNEY: How can you be so sure, Doctor? WITNESS: Because his brain was sitting in a jar on my desk. ATTORNEY: I see. But could the patient have still been alive, nevertheless? WITNESS: Yes. It is possible that he could have been alive and practicing law.

See also