templeos-info/public/Wb/Adam/Opt/Utils/Diff.HC.HTML

385 lines
38 KiB
HTML
Executable File

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="generator" content="TempleOS V5.03">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/style/templeos.css">
<script src="/script/templeos.js"></script>
<style type="text/css">
.cF0{color:#000000;background-color:#ffffff;}
.cF1{color:#0000aa;background-color:#ffffff;}
.cF2{color:#00aa00;background-color:#ffffff;}
.cF3{color:#00aaaa;background-color:#ffffff;}
.cF4{color:#aa0000;background-color:#ffffff;}
.cF5{color:#aa00aa;background-color:#ffffff;}
.cF6{color:#aa5500;background-color:#ffffff;}
.cF7{color:#aaaaaa;background-color:#ffffff;}
.cF8{color:#555555;background-color:#ffffff;}
.cF9{color:#5555ff;background-color:#ffffff;}
.cFA{color:#55ff55;background-color:#ffffff;}
.cFB{color:#55ffff;background-color:#ffffff;}
.cFC{color:#ff5555;background-color:#ffffff;}
.cFD{color:#ff55ff;background-color:#ffffff;}
.cFE{color:#ffff55;background-color:#ffffff;}
.cFF{color:#ffffff;background-color:#ffffff;}
</style>
</head>
<body>
<pre id="content">
<a name="l1"></a><span class=cF0>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>&quot;Cmd Line (Typically)&quot;</span><span class=cF0>
<a name="l2"></a>
<a name="l3"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>DS_USE_FILE1</span><span class=cF0> 0
<a name="l4"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>DS_USE_FILE2</span><span class=cF0> 1
<a name="l5"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>DS_REMAINDER_1</span><span class=cF0> 2
<a name="l6"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>DS_REMAINDER_2</span><span class=cF0> 3
<a name="l7"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>DS_ABORT_FILE</span><span class=cF0> 4
<a name="l8"></a>
<a name="l9"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>PopUpDiffMenu</span><span class=cF0>()
<a name="l10"></a>{
<a name="l11"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l12"></a> </span><span class=cF9>CDoc</span><span class=cF0> *doc=</span><span class=cF5>DocNew</span><span class=cF0>;
<a name="l13"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc,</span><span class=cF6>&quot;$CM+LX,2,4$$FG$$BT,\&quot;USE FILE1\&quot;,LE=DS_USE_FILE1$&quot;</span><span class=cF0>
<a name="l14"></a> </span><span class=cF6>&quot;$CM+LX,24,0$$CYAN$$BT,\&quot;USE FILE2\&quot;,LE=DS_USE_FILE2$&quot;</span><span class=cF0>
<a name="l15"></a> </span><span class=cF6>&quot;$CM+LX,2,4$$FG$$BT,\&quot;REMAINDER ALL FILE1\&quot;,LE=DS_REMAINDER_1$&quot;</span><span class=cF0>
<a name="l16"></a> </span><span class=cF6>&quot;$CM+LX,24,0$$CYAN$$BT,\&quot;REMAINDER ALL FILE2\&quot;,LE=DS_REMAINDER_2$&quot;</span><span class=cF0>
<a name="l17"></a> </span><span class=cF6>&quot;$CM+LX,2,4$$FG$$BT,\&quot;ABORT FILE\&quot;,LE=DS_ABORT_FILE$&quot;</span><span class=cF0>
<a name="l18"></a> </span><span class=cF6>&quot;$CM+LX,24,0$$FG$$BT,\&quot;ABORT ALL FILES\&quot;,LE=DOCM_CANCEL$\n&quot;</span><span class=cF0>);
<a name="l19"></a> i=</span><span class=cF5>PopUpMenu</span><span class=cF0>(doc);
<a name="l20"></a> </span><span class=cF5>DocDel</span><span class=cF0>(doc);
<a name="l21"></a> </span><span class=cF1>return</span><span class=cF0> i;
<a name="l22"></a>}
<a name="l23"></a>
<a name="l24"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>DiffEntriesCompare</span><span class=cF0>(</span><span class=cF9>CDocEntry</span><span class=cF0> *doc_e1,</span><span class=cF9>CDocEntry</span><span class=cF0> *doc_e2)
<a name="l25"></a>{
<a name="l26"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>StrCmp</span><span class=cF0>(doc_e1-&gt;tag,doc_e2-&gt;tag);
<a name="l27"></a>}
<a name="l28"></a>
<a name="l29"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>DF_MODIFIED</span><span class=cF0> 0x01
<a name="l30"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>DF_DONT_MODIFIED</span><span class=cF0> 0x02
<a name="l31"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>DF_REMAINDER_ALL_FILE1</span><span class=cF0> 0x04
<a name="l32"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>DF_REMAINDER_ALL_FILE2</span><span class=cF0> 0x08
<a name="l33"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>DF_ABORT_FILE</span><span class=cF0> 0x10
<a name="l34"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>DF_ABORT_ALL_FILES</span><span class=cF0> 0x20
<a name="l35"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>DF_NO_MORE_PMTS_THIS_FILE</span><span class=cF0> 0x40
<a name="l36"></a>
<a name="l37"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DiffSel</span><span class=cF0>(</span><span class=cF9>CDoc</span><span class=cF0> *doc,</span><span class=cF9>I64</span><span class=cF0> *_df_flags,</span><span class=cF9>I64</span><span class=cF0> j1_lo,</span><span class=cF9>I64</span><span class=cF0> j1_hi,
<a name="l38"></a> </span><span class=cF9>I64</span><span class=cF0> j2_lo,</span><span class=cF9>I64</span><span class=cF0> j2_hi,</span><span class=cF9>I64</span><span class=cF0> cnt1,</span><span class=cF9>I64</span><span class=cF0> cnt2,
<a name="l39"></a> </span><span class=cF9>CDocEntry</span><span class=cF0> **doc_unsorted1,</span><span class=cF9>CDocEntry</span><span class=cF0> **doc_unsorted2)
<a name="l40"></a>{
<a name="l41"></a> </span><span class=cF9>CDocEntry</span><span class=cF0> *doc_e,*doc_e1,*doc_e2;
<a name="l42"></a> </span><span class=cF1>Bool</span><span class=cF0> use_file1;
<a name="l43"></a> </span><span class=cF9>I64</span><span class=cF0> i,old_flags;
<a name="l44"></a> </span><span class=cF9>CDoc</span><span class=cF0> *cur_l;
<a name="l45"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>*_df_flags &amp; (</span><span class=cF3>DF_ABORT_FILE</span><span class=cF0>|</span><span class=cF3>DF_ABORT_ALL_FILES</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l46"></a> </span><span class=cF6>&quot;$RED$&quot;</span><span class=cF0>;
<a name="l47"></a> </span><span class=cF1>if</span><span class=cF0> (0&lt;=j1_lo&lt;cnt1)
<a name="l48"></a> </span><span class=cF6>&quot;%d,&quot;</span><span class=cF0>,doc_unsorted1[j1_lo]-&gt;y+1;
<a name="l49"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (0&lt;=j1_hi-1&lt;cnt1)
<a name="l50"></a> </span><span class=cF6>&quot;%d,&quot;</span><span class=cF0>,doc_unsorted1[j1_hi-1]-&gt;y+1;
<a name="l51"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l52"></a> </span><span class=cF6>&quot;***,&quot;</span><span class=cF0>;
<a name="l53"></a> </span><span class=cF1>if</span><span class=cF0> (0&lt;=j2_lo&lt;cnt2)
<a name="l54"></a> </span><span class=cF6>&quot;%d&quot;</span><span class=cF0>,doc_unsorted2[j2_lo]-&gt;y+1;
<a name="l55"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (0&lt;=j2_hi-1&lt;cnt2)
<a name="l56"></a> </span><span class=cF6>&quot;%d&quot;</span><span class=cF0>,doc_unsorted2[j2_hi-1]-&gt;y+1;
<a name="l57"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l58"></a> </span><span class=cF6>&quot;***&quot;</span><span class=cF0>;
<a name="l59"></a> </span><span class=cF6>&quot;---------------------$FG$\n&quot;</span><span class=cF0>;
<a name="l60"></a> </span><span class=cF1>if</span><span class=cF0> (j1_lo&lt;=0)
<a name="l61"></a> i=0;
<a name="l62"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l63"></a> i=j1_lo-1;
<a name="l64"></a> </span><span class=cF1>while</span><span class=cF0> (i&lt;j1_hi) {
<a name="l65"></a> </span><span class=cF1>if</span><span class=cF0> (cur_l=</span><span class=cF5>DocPut</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l66"></a> old_flags=cur_l-&gt;flags&amp;</span><span class=cF3>DOCF_PLAIN_TEXT</span><span class=cF0>;
<a name="l67"></a> cur_l-&gt;flags|=</span><span class=cF3>DOCF_PLAIN_TEXT</span><span class=cF0>;
<a name="l68"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l69"></a> </span><span class=cF6>&quot;%s&quot;</span><span class=cF0>,doc_unsorted1[i++]-&gt;tag;
<a name="l70"></a> </span><span class=cF1>if</span><span class=cF0> (cur_l)
<a name="l71"></a> cur_l-&gt;flags= cur_l-&gt;flags&amp;~</span><span class=cF3>DOCF_PLAIN_TEXT</span><span class=cF0> |old_flags;
<a name="l72"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l73"></a> }
<a name="l74"></a> </span><span class=cF6>&quot;$CYAN$&quot;</span><span class=cF0>;
<a name="l75"></a> </span><span class=cF1>if</span><span class=cF0> (j2_lo&lt;=0)
<a name="l76"></a> i=0;
<a name="l77"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l78"></a> i=j2_lo-1;
<a name="l79"></a> </span><span class=cF1>while</span><span class=cF0> (i&lt;j2_hi) {
<a name="l80"></a> </span><span class=cF1>if</span><span class=cF0> (cur_l=</span><span class=cF5>DocPut</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l81"></a> old_flags=cur_l-&gt;flags&amp;</span><span class=cF3>DOCF_PLAIN_TEXT</span><span class=cF0>;
<a name="l82"></a> cur_l-&gt;flags|=</span><span class=cF3>DOCF_PLAIN_TEXT</span><span class=cF0>;
<a name="l83"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l84"></a> </span><span class=cF6>&quot;%s&quot;</span><span class=cF0>,doc_unsorted2[i++]-&gt;tag;
<a name="l85"></a> </span><span class=cF1>if</span><span class=cF0> (cur_l)
<a name="l86"></a> cur_l-&gt;flags= cur_l-&gt;flags&amp;~</span><span class=cF3>DOCF_PLAIN_TEXT</span><span class=cF0> |old_flags;
<a name="l87"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l88"></a> }
<a name="l89"></a> </span><span class=cF6>&quot;$FG$&quot;</span><span class=cF0>;
<a name="l90"></a>
<a name="l91"></a> use_file1=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l92"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>*_df_flags &amp; </span><span class=cF3>DF_NO_MORE_PMTS_THIS_FILE</span><span class=cF7>)</span><span class=cF0>) {
<a name="l93"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>PopUpDiffMenu</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l94"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>DS_USE_FILE1</span><span class=cF0>:
<a name="l95"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l96"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>DS_USE_FILE2</span><span class=cF0>:
<a name="l97"></a> use_file1=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l98"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l99"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>DS_REMAINDER_1</span><span class=cF0>:
<a name="l100"></a> *_df_flags=*_df_flags&amp;~</span><span class=cF3>DF_REMAINDER_ALL_FILE2</span><span class=cF0>|
<a name="l101"></a> </span><span class=cF3>DF_REMAINDER_ALL_FILE1</span><span class=cF0>|</span><span class=cF3>DF_NO_MORE_PMTS_THIS_FILE</span><span class=cF0>;
<a name="l102"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l103"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>DS_REMAINDER_2</span><span class=cF0>:
<a name="l104"></a> *_df_flags=*_df_flags&amp;~</span><span class=cF3>DF_REMAINDER_ALL_FILE1</span><span class=cF0>|
<a name="l105"></a> </span><span class=cF3>DF_REMAINDER_ALL_FILE2</span><span class=cF0>|</span><span class=cF3>DF_NO_MORE_PMTS_THIS_FILE</span><span class=cF0>;
<a name="l106"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l107"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>DS_ABORT_FILE</span><span class=cF0>:
<a name="l108"></a> *_df_flags|=</span><span class=cF3>DF_DONT_MODIFIED</span><span class=cF0>|</span><span class=cF3>DF_ABORT_FILE</span><span class=cF0>|
<a name="l109"></a> </span><span class=cF3>DF_NO_MORE_PMTS_THIS_FILE</span><span class=cF0>;
<a name="l110"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l111"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l112"></a> *_df_flags|=</span><span class=cF3>DF_DONT_MODIFIED</span><span class=cF0>|</span><span class=cF3>DF_ABORT_ALL_FILES</span><span class=cF0>|
<a name="l113"></a> </span><span class=cF3>DF_NO_MORE_PMTS_THIS_FILE</span><span class=cF0>;
<a name="l114"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l115"></a> }
<a name="l116"></a> </span><span class=cF1>if</span><span class=cF0> (*_df_flags &amp; </span><span class=cF3>DF_REMAINDER_ALL_FILE2</span><span class=cF0> &amp;&amp;
<a name="l117"></a> !</span><span class=cF7>(</span><span class=cF0>*_df_flags &amp; (</span><span class=cF3>DF_DONT_MODIFIED</span><span class=cF0>|</span><span class=cF3>DF_REMAINDER_ALL_FILE1</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0>)
<a name="l118"></a> use_file1=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l119"></a> </span><span class=cF1>if</span><span class=cF0> (!use_file1) {
<a name="l120"></a> *_df_flags|=</span><span class=cF3>DF_MODIFIED</span><span class=cF0>;
<a name="l121"></a> doc_e1=doc_unsorted1[j1_lo]-&gt;last;
<a name="l122"></a> </span><span class=cF1>if</span><span class=cF0> (j1_lo&lt;j1_hi) </span><span class=cF7>{</span><span class=cF0>
<a name="l123"></a> doc_e=doc_unsorted1[j1_lo];
<a name="l124"></a> </span><span class=cF1>while</span><span class=cF0> (doc_e!=doc_unsorted1[j1_hi]) {
<a name="l125"></a> doc_e2=doc_e-&gt;next;
<a name="l126"></a> </span><span class=cF5>DocEntryDel</span><span class=cF0>(doc,doc_e);
<a name="l127"></a> doc_e=doc_e2;
<a name="l128"></a> }
<a name="l129"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l130"></a> </span><span class=cF1>if</span><span class=cF0> (j2_lo&lt;j2_hi) </span><span class=cF7>{</span><span class=cF0>
<a name="l131"></a> doc_e=doc_unsorted2[j2_lo];
<a name="l132"></a> </span><span class=cF1>while</span><span class=cF0> (doc_e!=doc_unsorted2[j2_hi]) {
<a name="l133"></a> doc_e2=</span><span class=cF5>DocEntryCopy</span><span class=cF0>(doc,doc_e);
<a name="l134"></a> </span><span class=cF5>QueIns</span><span class=cF0>(doc_e2,doc_e1);
<a name="l135"></a> doc_e1=doc_e2;
<a name="l136"></a> doc_e=doc_e-&gt;next;
<a name="l137"></a> }
<a name="l138"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l139"></a> }
<a name="l140"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l141"></a>}
<a name="l142"></a>
<a name="l143"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>DiffSub</span><span class=cF0>(</span><span class=cF9>CDoc</span><span class=cF0> *doc,</span><span class=cF9>I64</span><span class=cF0> *_df_flags,</span><span class=cF9>I64</span><span class=cF0> j1_lo,</span><span class=cF9>I64</span><span class=cF0> j1_hi,</span><span class=cF9>I64</span><span class=cF0> j2_lo,</span><span class=cF9>I64</span><span class=cF0> j2_hi,
<a name="l144"></a> </span><span class=cF9>I64</span><span class=cF0> cnt1,</span><span class=cF9>I64</span><span class=cF0> cnt2,</span><span class=cF9>CDocEntry</span><span class=cF0> **doc_sorted1,</span><span class=cF9>CDocEntry</span><span class=cF0> **doc_sorted2,
<a name="l145"></a> </span><span class=cF9>CDocEntry</span><span class=cF0> **doc_unsorted1,</span><span class=cF9>CDocEntry</span><span class=cF0> **doc_unsorted2)
<a name="l146"></a>{
<a name="l147"></a> </span><span class=cF9>I64</span><span class=cF0> i,i1=0,i2=0,i2b,j1,j2,n,
<a name="l148"></a> best_j1,best_j2,best_score=0,score;
<a name="l149"></a> </span><span class=cF1>Bool</span><span class=cF0> res=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l150"></a>
<a name="l151"></a> </span><span class=cF1>if</span><span class=cF0> (j1_lo&gt;=j1_hi || j2_lo&gt;=j2_hi) </span><span class=cF7>{</span><span class=cF0>
<a name="l152"></a> </span><span class=cF1>if</span><span class=cF0> (j1_lo&lt;j1_hi || j2_lo&lt;j2_hi) {
<a name="l153"></a> </span><span class=cF5>DiffSel</span><span class=cF0>(doc,_df_flags,j1_lo,j1_hi,j2_lo,j2_hi,cnt1,cnt2,
<a name="l154"></a> doc_unsorted1,doc_unsorted2);
<a name="l155"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l156"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l157"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l158"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l159"></a>
<a name="l160"></a> </span><span class=cF2>//Locate longest matching str in intervals</span><span class=cF0>
<a name="l161"></a> </span><span class=cF1>while</span><span class=cF0> (i1&lt;cnt1 &amp;&amp; i2&lt;cnt2) </span><span class=cF7>{</span><span class=cF0>
<a name="l162"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>j1_lo&lt;=doc_sorted1[i1]-&gt;user_data&lt;j1_hi</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF2>//user_data is the new y</span><span class=cF0>
<a name="l163"></a> i1++;
<a name="l164"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>j2_lo&lt;=doc_sorted2[i2]-&gt;user_data&lt;j2_hi</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF2>//user_data is new y</span><span class=cF0>
<a name="l165"></a> i2++;
<a name="l166"></a> </span><span class=cF1>else</span><span class=cF0> {
<a name="l167"></a> i=</span><span class=cF5>StrCmp</span><span class=cF0>(doc_sorted1[i1]-&gt;tag,doc_sorted2[i2]-&gt;tag);
<a name="l168"></a> </span><span class=cF1>if</span><span class=cF0> (i&gt;0)
<a name="l169"></a> i2++;
<a name="l170"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (i&lt;0)
<a name="l171"></a> i1++;
<a name="l172"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l173"></a> i2b=i2;
<a name="l174"></a> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cF5>StrCmp</span><span class=cF7>(</span><span class=cF0>doc_sorted1[i1]-&gt;tag,doc_sorted2[i2]-&gt;tag</span><span class=cF7>)</span><span class=cF0>) {
<a name="l175"></a> </span><span class=cF1>if</span><span class=cF0> (j2_lo&lt;=doc_sorted2[i2]-&gt;user_data&lt;j2_hi) </span><span class=cF7>{</span><span class=cF2>//user_data is the new y</span><span class=cF0>
<a name="l176"></a> score=0;
<a name="l177"></a> j1=doc_sorted1[i1]-&gt;user_data; </span><span class=cF2>//user_data is the new y</span><span class=cF0>
<a name="l178"></a> j2=doc_sorted2[i2]-&gt;user_data; </span><span class=cF2>//user_data is the new y</span><span class=cF0>
<a name="l179"></a> n=j1_hi-j1;
<a name="l180"></a> </span><span class=cF1>if</span><span class=cF0> (j2_hi-j2&lt;n)
<a name="l181"></a> n=j2_hi-j2;
<a name="l182"></a> </span><span class=cF1>while</span><span class=cF0> (score&lt;n) {
<a name="l183"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrCmp</span><span class=cF7>(</span><span class=cF0>doc_unsorted1[j1+score]-&gt;tag,
<a name="l184"></a> doc_unsorted2[j2+score]-&gt;tag</span><span class=cF7>)</span><span class=cF0>)
<a name="l185"></a> score++;
<a name="l186"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l187"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l188"></a> }
<a name="l189"></a> </span><span class=cF1>if</span><span class=cF0> (score&gt;best_score) {
<a name="l190"></a> best_score=score;
<a name="l191"></a> best_j1=j1;
<a name="l192"></a> best_j2=j2;
<a name="l193"></a> }
<a name="l194"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l195"></a> i2++;
<a name="l196"></a> </span><span class=cF1>if</span><span class=cF0> (i2&gt;=cnt2)
<a name="l197"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l198"></a> }
<a name="l199"></a> i2=i2b;
<a name="l200"></a> i1++;
<a name="l201"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l202"></a> }
<a name="l203"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l204"></a> </span><span class=cF1>if</span><span class=cF0> (!best_score) </span><span class=cF7>{</span><span class=cF0>
<a name="l205"></a> </span><span class=cF5>DiffSel</span><span class=cF0>(doc,_df_flags,j1_lo,j1_hi,j2_lo,j2_hi,cnt1,cnt2,
<a name="l206"></a> doc_unsorted1,doc_unsorted2);
<a name="l207"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l208"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l209"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>DiffSub</span><span class=cF7>(</span><span class=cF0>doc,_df_flags,j1_lo,best_j1,j2_lo,best_j2,cnt1,cnt2,
<a name="l210"></a> doc_sorted1,doc_sorted2,doc_unsorted1,doc_unsorted2</span><span class=cF7>)</span><span class=cF0>)
<a name="l211"></a> res=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l212"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>DiffSub</span><span class=cF7>(</span><span class=cF0>doc,_df_flags,best_j1+best_score,j1_hi,best_j2+best_score,
<a name="l213"></a> j2_hi,cnt1,cnt2,
<a name="l214"></a> doc_sorted1,doc_sorted2,doc_unsorted1,doc_unsorted2</span><span class=cF7>)</span><span class=cF0>)
<a name="l215"></a> res=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l216"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l217"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l218"></a>}
<a name="l219"></a>
<a name="l220"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>DiffBins</span><span class=cF0>(</span><span class=cF9>CDoc</span><span class=cF0> *doc1,</span><span class=cF9>CDoc</span><span class=cF0> *doc2)
<a name="l221"></a>{
<a name="l222"></a> </span><span class=cF9>CDocBin</span><span class=cF0> *tmpb1=doc1-&gt;bin_head.next,
<a name="l223"></a> *tmpb2=doc2-&gt;bin_head.next;
<a name="l224"></a>
<a name="l225"></a> </span><span class=cF1>if</span><span class=cF0> (tmpb1-&gt;last-&gt;last-&gt;num!=tmpb2-&gt;last-&gt;last-&gt;num)
<a name="l226"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l227"></a> </span><span class=cF1>while</span><span class=cF0> (tmpb1!=&amp;doc1-&gt;bin_head) </span><span class=cF7>{</span><span class=cF0>
<a name="l228"></a> </span><span class=cF1>if</span><span class=cF0> (tmpb1-&gt;size!=tmpb2-&gt;size ||
<a name="l229"></a> </span><span class=cF5>MemCmp</span><span class=cF7>(</span><span class=cF0>tmpb1-&gt;data,tmpb2-&gt;data,tmpb1-&gt;size</span><span class=cF7>)</span><span class=cF0>)
<a name="l230"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l231"></a> tmpb1=tmpb1-&gt;next;
<a name="l232"></a> tmpb2=tmpb2-&gt;next;
<a name="l233"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l234"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l235"></a>}
<a name="l236"></a>
<a name="l237"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>Diff</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *dst_file,</span><span class=cF1>U8</span><span class=cF0> *src_file,</span><span class=cF9>I64</span><span class=cF0> *_df_flags=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l238"></a>{</span><span class=cF2>//Report differences between two files and merge differences</span><span class=cF0>
<a name="l239"></a></span><span class=cF2>//from src_file to dst_file. Don't use _df_flags arg. (Used by </span><a href="/Wb/Adam/Opt/Utils/Merge.HC.HTML#l37"><span class=cF4>Merge</span></a><span class=cF2>().)</span><span class=cF0>
<a name="l240"></a> </span><span class=cF9>CDoc</span><span class=cF0> *doc1=</span><span class=cF5>DocRead</span><span class=cF0>(dst_file,</span><span class=cF3>DOCF_PLAIN_TEXT_TABS</span><span class=cF0>|</span><span class=cF3>DOCF_NO_CURSOR</span><span class=cF0>),
<a name="l241"></a> *doc2=</span><span class=cF5>DocRead</span><span class=cF0>(src_file,</span><span class=cF3>DOCF_PLAIN_TEXT_TABS</span><span class=cF0>|</span><span class=cF3>DOCF_NO_CURSOR</span><span class=cF0>);
<a name="l242"></a> </span><span class=cF9>CDocEntry</span><span class=cF0> *doc_e,**doc_sorted1,**doc_sorted2,**doc_unsorted1,**doc_unsorted2;
<a name="l243"></a> </span><span class=cF9>I64</span><span class=cF0> i,cnt1=0,cnt2=0,df_flags;
<a name="l244"></a> </span><span class=cF1>Bool</span><span class=cF0> res=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l245"></a>
<a name="l246"></a> </span><span class=cF1>if</span><span class=cF0> (_df_flags)
<a name="l247"></a> df_flags=*_df_flags;
<a name="l248"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l249"></a> df_flags=0;
<a name="l250"></a> df_flags&amp;=</span><span class=cF3>DF_ABORT_ALL_FILES</span><span class=cF0>;
<a name="l251"></a>
<a name="l252"></a> doc_e=doc1-&gt;head.next;
<a name="l253"></a> </span><span class=cF1>while</span><span class=cF0> (doc_e!=doc1) </span><span class=cF7>{</span><span class=cF0>
<a name="l254"></a> </span><span class=cF1>if</span><span class=cF0> (doc_e-&gt;type_u8==</span><span class=cF3>DOCT_TEXT</span><span class=cF0>)
<a name="l255"></a> doc_e-&gt;user_data=cnt1++; </span><span class=cF2>//user_data is the new y</span><span class=cF0>
<a name="l256"></a> doc_e=doc_e-&gt;next;
<a name="l257"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l258"></a>
<a name="l259"></a> doc_e=doc2-&gt;head.next;
<a name="l260"></a> </span><span class=cF1>while</span><span class=cF0> (doc_e!=doc2) </span><span class=cF7>{</span><span class=cF0>
<a name="l261"></a> </span><span class=cF1>if</span><span class=cF0> (doc_e-&gt;type_u8==</span><span class=cF3>DOCT_TEXT</span><span class=cF0>)
<a name="l262"></a> doc_e-&gt;user_data=cnt2++; </span><span class=cF2>//user_data is the new y</span><span class=cF0>
<a name="l263"></a> doc_e=doc_e-&gt;next;
<a name="l264"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l265"></a>
<a name="l266"></a> doc_sorted1=</span><span class=cF5>MAlloc</span><span class=cF0>(cnt1*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDocEntry</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>);
<a name="l267"></a> doc_unsorted1=</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>cnt1+1</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDocEntry</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>);
<a name="l268"></a> i=0;
<a name="l269"></a> doc_e=doc1-&gt;head.next;
<a name="l270"></a> </span><span class=cF1>while</span><span class=cF0> (doc_e!=doc1) </span><span class=cF7>{</span><span class=cF0>
<a name="l271"></a> </span><span class=cF1>if</span><span class=cF0> (doc_e-&gt;type_u8==</span><span class=cF3>DOCT_TEXT</span><span class=cF0>) {
<a name="l272"></a> doc_sorted1[i]=doc_e;
<a name="l273"></a> doc_unsorted1[i++]=doc_e;
<a name="l274"></a> }
<a name="l275"></a> doc_e=doc_e-&gt;next;
<a name="l276"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l277"></a> doc_unsorted1[i]=doc1;
<a name="l278"></a> </span><span class=cF5>QSortI64</span><span class=cF0>(doc_sorted1,cnt1,&amp;</span><span class=cF5>DiffEntriesCompare</span><span class=cF0>);
<a name="l279"></a>
<a name="l280"></a> doc_sorted2=</span><span class=cF5>MAlloc</span><span class=cF0>(cnt2*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDocEntry</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>);
<a name="l281"></a> doc_unsorted2=</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>cnt2+1</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDocEntry</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>);
<a name="l282"></a> i=0;
<a name="l283"></a> doc_e=doc2-&gt;head.next;
<a name="l284"></a> </span><span class=cF1>while</span><span class=cF0> (doc_e!=doc2) </span><span class=cF7>{</span><span class=cF0>
<a name="l285"></a> </span><span class=cF1>if</span><span class=cF0> (doc_e-&gt;type_u8==</span><span class=cF3>DOCT_TEXT</span><span class=cF0>) {
<a name="l286"></a> doc_sorted2[i]=doc_e;
<a name="l287"></a> doc_unsorted2[i++]=doc_e;
<a name="l288"></a> }
<a name="l289"></a> doc_e=doc_e-&gt;next;
<a name="l290"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l291"></a> doc_unsorted2[i]=doc2;
<a name="l292"></a> </span><span class=cF5>QSortI64</span><span class=cF0>(doc_sorted2,cnt2,&amp;</span><span class=cF5>DiffEntriesCompare</span><span class=cF0>);
<a name="l293"></a>
<a name="l294"></a> res=</span><span class=cF5>DiffSub</span><span class=cF0>(doc1,&amp;df_flags,0,cnt1,0,cnt2,cnt1,cnt2,
<a name="l295"></a> doc_sorted1,doc_sorted2,doc_unsorted1,doc_unsorted2);
<a name="l296"></a> </span><span class=cF1>if</span><span class=cF0> (df_flags&amp;</span><span class=cF3>DF_MODIFIED</span><span class=cF0> &amp;&amp; !</span><span class=cF7>(</span><span class=cF0>df_flags&amp;</span><span class=cF3>DF_DONT_MODIFIED</span><span class=cF7>)</span><span class=cF0>)
<a name="l297"></a> </span><span class=cF5>DocWrite</span><span class=cF0>(doc1);
<a name="l298"></a>
<a name="l299"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>DiffBins</span><span class=cF7>(</span><span class=cF0>doc1,doc2</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l300"></a> </span><span class=cF6>&quot;$RED$Bin Data is Different$FG$\n&quot;</span><span class=cF0>;
<a name="l301"></a> res=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l302"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l303"></a>
<a name="l304"></a> </span><span class=cF5>DocDel</span><span class=cF0>(doc1);
<a name="l305"></a> </span><span class=cF5>DocDel</span><span class=cF0>(doc2);
<a name="l306"></a> </span><span class=cF5>Free</span><span class=cF0>(doc_sorted1);
<a name="l307"></a> </span><span class=cF5>Free</span><span class=cF0>(doc_sorted2);
<a name="l308"></a> </span><span class=cF5>Free</span><span class=cF0>(doc_unsorted1);
<a name="l309"></a> </span><span class=cF5>Free</span><span class=cF0>(doc_unsorted2);
<a name="l310"></a> </span><span class=cF1>if</span><span class=cF0> (_df_flags)
<a name="l311"></a> *_df_flags=df_flags;
<a name="l312"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l313"></a>}
<a name="l314"></a>
<a name="l315"></a>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>&quot;Cmd Line (Typically);Info&quot;</span><span class=cF0>
<a name="l316"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ZRepCompare</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0> *e1,</span><span class=cF9>CDirEntry</span><span class=cF0> *e2)
<a name="l317"></a>{
<a name="l318"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>SignI64</span><span class=cF0>(e2-&gt;user_data</span><span class=cF7>(</span><span class=cF1>F64</span><span class=cF7>)</span><span class=cF0>-e1-&gt;user_data</span><span class=cF7>(</span><span class=cF1>F64</span><span class=cF7>)</span><span class=cF0>);
<a name="l319"></a>}
<a name="l320"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>ZipRep</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *files_find_mask=</span><span class=cF6>&quot;/*&quot;</span><span class=cF0>,</span><span class=cF1>U8</span><span class=cF0> *fu_flags=</span><span class=cF3>NULL</span><span class=cF0>,
<a name="l321"></a> </span><span class=cF1>Bool</span><span class=cF0> just_text_not_graphics=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l322"></a>{</span><span class=cF2>//Report file compressibility.</span><span class=cF0>
<a name="l323"></a></span><span class=cF2>//Dft is just src files. (Used to spot</span><span class=cF0>
<a name="l324"></a> </span><span class=cF2>//src files with redundancy in them.)</span><span class=cF0>
<a name="l325"></a> </span><span class=cF9>I64</span><span class=cF0> i=0,cnt,size,fuf_flags=0;
<a name="l326"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *tmpde,*tmpde1,**sort_buf;
<a name="l327"></a> </span><span class=cF1>U8</span><span class=cF0> *buf;
<a name="l328"></a> </span><span class=cF9>CArcCompress</span><span class=cF0> *arc;
<a name="l329"></a> </span><span class=cF5>ScanFlags</span><span class=cF0>(&amp;fuf_flags,</span><span class=cF5>Define</span><span class=cF7>(</span><span class=cF6>&quot;ST_FILE_UTIL_FLAGS&quot;</span><span class=cF7>)</span><span class=cF0>,</span><span class=cF6>&quot;+r+F+S&quot;</span><span class=cF0>);
<a name="l330"></a> </span><span class=cF5>ScanFlags</span><span class=cF0>(&amp;fuf_flags,</span><span class=cF5>Define</span><span class=cF7>(</span><span class=cF6>&quot;ST_FILE_UTIL_FLAGS&quot;</span><span class=cF7>)</span><span class=cF0>,fu_flags);
<a name="l331"></a> tmpde=tmpde1=</span><span class=cF5>FilesFind</span><span class=cF0>(files_find_mask,fuf_flags);
<a name="l332"></a> cnt=</span><span class=cF5>FileCnt</span><span class=cF0>(tmpde);
<a name="l333"></a> sort_buf=</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDirEntry</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>*cnt);
<a name="l334"></a> </span><span class=cF1>while</span><span class=cF0> (tmpde) </span><span class=cF7>{</span><span class=cF0>
<a name="l335"></a> sort_buf[i++]=tmpde;
<a name="l336"></a> buf=</span><span class=cF5>FileRead</span><span class=cF0>(tmpde-&gt;full_name,&amp;size);
<a name="l337"></a> </span><span class=cF1>if</span><span class=cF0> (just_text_not_graphics)
<a name="l338"></a> size=</span><span class=cF5>StrLen</span><span class=cF0>(buf);
<a name="l339"></a> arc=</span><span class=cF5>CompressBuf</span><span class=cF0>(buf,size);
<a name="l340"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l341"></a> tmpde-&gt;user_data(</span><span class=cF1>F64</span><span class=cF0>)=100.0*arc-&gt;compressed_size/arc-&gt;expanded_size;
<a name="l342"></a> </span><span class=cF5>Free</span><span class=cF0>(arc);
<a name="l343"></a> tmpde=tmpde-&gt;next;
<a name="l344"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l345"></a> </span><span class=cF5>QSortI64</span><span class=cF0>(sort_buf,cnt,&amp;</span><span class=cF5>ZRepCompare</span><span class=cF0>);
<a name="l346"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;cnt;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l347"></a> </span><span class=cF6>&quot;%4.1f%% %04X &quot;</span><span class=cF0>,sort_buf[i]-&gt;user_data,sort_buf[i]-&gt;size;
<a name="l348"></a> </span><span class=cF5>PutFileLink</span><span class=cF0>(sort_buf[i]-&gt;full_name);
<a name="l349"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l350"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l351"></a> </span><span class=cF5>Free</span><span class=cF0>(sort_buf);
<a name="l352"></a> </span><span class=cF5>DirTreeDel</span><span class=cF0>(tmpde1);
<a name="l353"></a>}
</span></pre></body>
</html>