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

188 lines
20 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;DolDoc/Cmd Line (Typically)&quot;</span><span class=cF0>
<a name="l2"></a>
<a name="l3"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>CursorRemFile</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *filename)
<a name="l4"></a>{</span><span class=cF2>//Rem ASCII 5 cursor from one file.</span><span class=cF0>
<a name="l5"></a> </span><span class=cF9>CDoc</span><span class=cF0> *doc=</span><span class=cF5>DocRead</span><span class=cF0>(filename,</span><span class=cF3>DOCF_PLAIN_TEXT</span><span class=cF0>|</span><span class=cF3>DOCF_NO_CURSOR</span><span class=cF0>);
<a name="l6"></a> </span><span class=cF5>DocWrite</span><span class=cF0>(doc);
<a name="l7"></a> </span><span class=cF5>DocDel</span><span class=cF0>(doc);
<a name="l8"></a>}
<a name="l9"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>CursorRem</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>)
<a name="l10"></a>{</span><span class=cF2>//Rem ASCII 5 cursor.</span><span class=cF0>
<a name="l11"></a> </span><span class=cF9>I64</span><span class=cF0> fuf_flags=0;
<a name="l12"></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+T+f+F+O&quot;</span><span class=cF0>);
<a name="l13"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *tmpde=</span><span class=cF5>FilesFind</span><span class=cF0>(files_find_mask,fuf_flags),*tmpde1=tmpde;
<a name="l14"></a> </span><span class=cF1>while</span><span class=cF0> (tmpde) </span><span class=cF7>{</span><span class=cF0>
<a name="l15"></a> </span><span class=cF5>CursorRemFile</span><span class=cF0>(tmpde-&gt;full_name);
<a name="l16"></a> </span><span class=cF5>Touch</span><span class=cF0>(tmpde-&gt;full_name,</span><span class=cF6>&quot;&quot;</span><span class=cF0>,,tmpde-&gt;datetime);
<a name="l17"></a> tmpde=tmpde-&gt;next;
<a name="l18"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l19"></a> </span><span class=cF5>DirTreeDel</span><span class=cF0>(tmpde1);
<a name="l20"></a>}
<a name="l21"></a>
<a name="l22"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>CollapseFile</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *filename,</span><span class=cF1>Bool</span><span class=cF0> collapse=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l23"></a>{</span><span class=cF2>//Collapse </span><a href="/Wb/Doc/DolDocOverview.DD.HTML#l1"><span class=cF4>DolDoc</span></a><span class=cF2> trees in one file.</span><span class=cF0>
<a name="l24"></a> </span><span class=cF9>CDoc</span><span class=cF0> *doc=</span><span class=cF5>DocRead</span><span class=cF0>(filename,</span><span class=cF3>DOCF_NO_CURSOR</span><span class=cF0>);
<a name="l25"></a> </span><span class=cF5>DocCollapse</span><span class=cF0>(collapse,doc);
<a name="l26"></a> </span><span class=cF5>DocWrite</span><span class=cF0>(doc);
<a name="l27"></a> </span><span class=cF5>DocDel</span><span class=cF0>(doc);
<a name="l28"></a>}
<a name="l29"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Collapse</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>,
<a name="l30"></a> </span><span class=cF1>Bool</span><span class=cF0> collapse=</span><span class=cF3>TRUE</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="l31"></a>{</span><span class=cF2>//Collapse </span><a href="/Wb/Doc/DolDocOverview.DD.HTML#l1"><span class=cF4>DolDoc</span></a><span class=cF2> trees.</span><span class=cF0>
<a name="l32"></a> </span><span class=cF9>I64</span><span class=cF0> fuf_flags=0;
<a name="l33"></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+F+$+O&quot;</span><span class=cF0>);
<a name="l34"></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="l35"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *tmpde=</span><span class=cF5>FilesFind</span><span class=cF0>(files_find_mask,fuf_flags),*tmpde1=tmpde;
<a name="l36"></a> </span><span class=cF1>while</span><span class=cF0> (tmpde &amp;&amp; !</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;fuf_flags,</span><span class=cF3>FUf_CANCEL</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l37"></a> </span><span class=cF5>CollapseFile</span><span class=cF0>(tmpde-&gt;full_name,collapse);
<a name="l38"></a> </span><span class=cF5>Touch</span><span class=cF0>(tmpde-&gt;full_name,</span><span class=cF6>&quot;&quot;</span><span class=cF0>,,tmpde-&gt;datetime);
<a name="l39"></a> tmpde=tmpde-&gt;next;
<a name="l40"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l41"></a> </span><span class=cF5>DirTreeDel</span><span class=cF0>(tmpde1);
<a name="l42"></a>}
<a name="l43"></a>
<a name="l44"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>DocOptEntry</span><span class=cF0>(</span><span class=cF9>CDoc</span><span class=cF0> *,</span><span class=cF9>CDocEntry</span><span class=cF0> *doc_e,</span><span class=cF9>I64</span><span class=cF0> fuf_flags)
<a name="l45"></a>{
<a name="l46"></a> </span><span class=cF1>U8</span><span class=cF0> *st,*st2,**_dst;
<a name="l47"></a> </span><span class=cF9>I64</span><span class=cF0> i,res=0;
<a name="l48"></a>
<a name="l49"></a> </span><span class=cF1>if</span><span class=cF0> (doc_e-&gt;de_flags&amp;</span><span class=cF3>DOCEF_LINK</span><span class=cF0> &amp;&amp; doc_e-&gt;de_flags&amp;</span><span class=cF7>(</span><span class=cF3>DOCEF_AUX_STR</span><span class=cF0>|</span><span class=cF3>DOCEF_TAG</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l50"></a> </span><span class=cF1>if</span><span class=cF0> (doc_e-&gt;de_flags &amp; </span><span class=cF3>DOCEF_AUX_STR</span><span class=cF0> &amp;&amp; doc_e-&gt;de_flags &amp; </span><span class=cF3>DOCEF_TAG</span><span class=cF0> &amp;&amp;
<a name="l51"></a> !</span><span class=cF5>MemCmp</span><span class=cF7>(</span><span class=cF0>doc_e-&gt;aux_str,</span><span class=cF6>&quot;FI:&quot;</span><span class=cF0>,3</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l52"></a> !</span><span class=cF5>StrCmp</span><span class=cF7>(</span><span class=cF0>doc_e-&gt;aux_str+3,doc_e-&gt;tag</span><span class=cF7>)</span><span class=cF0>) {
<a name="l53"></a> </span><span class=cF5>Free</span><span class=cF0>(doc_e-&gt;aux_str);
<a name="l54"></a> doc_e-&gt;aux_str=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l55"></a> doc_e-&gt;de_flags&amp;=~</span><span class=cF3>DOCEF_AUX_STR</span><span class=cF0>;
<a name="l56"></a> res++;
<a name="l57"></a> }
<a name="l58"></a> </span><span class=cF1>if</span><span class=cF0> (doc_e-&gt;de_flags &amp; </span><span class=cF3>DOCEF_AUX_STR</span><span class=cF0>)
<a name="l59"></a> _dst=&amp;doc_e-&gt;aux_str;
<a name="l60"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l61"></a> _dst=&amp;doc_e-&gt;tag;
<a name="l62"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrMatch</span><span class=cF7>(</span><span class=cF6>&quot;.Z&quot;</span><span class=cF0>,*_dst</span><span class=cF7>)</span><span class=cF0>) {
<a name="l63"></a> st=</span><span class=cF5>DocLinkFile</span><span class=cF0>(*_dst);
<a name="l64"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>FileFind</span><span class=cF7>(</span><span class=cF0>st</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l65"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>IsDotZ</span><span class=cF7>(</span><span class=cF0>st</span><span class=cF7>)</span><span class=cF0>)
<a name="l66"></a> st[</span><span class=cF5>StrLen</span><span class=cF0>(st)-2]=0;
<a name="l67"></a> i=</span><span class=cF5>StrLen</span><span class=cF0>(st);
<a name="l68"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>st2=</span><span class=cF5>StrMatch</span><span class=cF0>(st,*_dst)</span><span class=cF7>)</span><span class=cF0> &amp;&amp; st2[i]==</span><span class=cF6>'.'</span><span class=cF0> &amp;&amp; st2[i+1]==</span><span class=cF6>'Z'</span><span class=cF0>) {
<a name="l69"></a> </span><span class=cF5>StrCpy</span><span class=cF0>(st2+i,st2+i+2);
<a name="l70"></a> res++;
<a name="l71"></a> }
<a name="l72"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l73"></a> </span><span class=cF5>Free</span><span class=cF0>(st);
<a name="l74"></a> }
<a name="l75"></a> </span><span class=cF1>if</span><span class=cF0> (fuf_flags&amp;</span><span class=cF3>FUF_RISKY</span><span class=cF0>) {
<a name="l76"></a> </span><span class=cF1>if</span><span class=cF0> (doc_e-&gt;de_flags &amp; </span><span class=cF3>DOCEF_AUX_STR</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l77"></a> </span><span class=cF1>if</span><span class=cF0> (st=</span><span class=cF5>StrMatch</span><span class=cF7>(</span><span class=cF6>&quot;.Z&quot;</span><span class=cF0>,doc_e-&gt;aux_str</span><span class=cF7>)</span><span class=cF0>) {
<a name="l78"></a> </span><span class=cF5>StrCpy</span><span class=cF0>(st,st+2);
<a name="l79"></a> res++;
<a name="l80"></a> }
<a name="l81"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l82"></a> </span><span class=cF1>if</span><span class=cF0> (doc_e-&gt;de_flags&amp;</span><span class=cF3>DOCEF_TAG</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l83"></a> </span><span class=cF1>if</span><span class=cF0> (st=</span><span class=cF5>StrMatch</span><span class=cF7>(</span><span class=cF6>&quot;.Z&quot;</span><span class=cF0>,doc_e-&gt;tag</span><span class=cF7>)</span><span class=cF0>) {
<a name="l84"></a> </span><span class=cF5>StrCpy</span><span class=cF0>(st,st+2);
<a name="l85"></a> res++;
<a name="l86"></a> }
<a name="l87"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l88"></a> }
<a name="l89"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l90"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l91"></a>}
<a name="l92"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>DocOptDoc</span><span class=cF0>(</span><span class=cF9>CDoc</span><span class=cF0> *doc,</span><span class=cF9>I64</span><span class=cF0> fuf_flags)
<a name="l93"></a>{</span><span class=cF2>//Optimize Doc.</span><span class=cF0>
<a name="l94"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock=</span><span class=cF5>DocLock</span><span class=cF0>(doc);
<a name="l95"></a> </span><span class=cF9>I64</span><span class=cF0> res=0;
<a name="l96"></a> </span><span class=cF9>CDocEntry</span><span class=cF0> *doc_e,*doc_e1,*doc_e_last;
<a name="l97"></a> </span><span class=cF5>DocRecalc</span><span class=cF0>(doc);
<a name="l98"></a> doc_e_last=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l99"></a> doc_e=doc-&gt;head.next;
<a name="l100"></a> </span><span class=cF1>while</span><span class=cF0> (doc_e!=doc) </span><span class=cF7>{</span><span class=cF0>
<a name="l101"></a> doc_e1=doc_e-&gt;next;
<a name="l102"></a> </span><span class=cF1>if</span><span class=cF0> (res+=</span><span class=cF5>DocOptEntry</span><span class=cF7>(</span><span class=cF0>doc,doc_e,fuf_flags</span><span class=cF7>)</span><span class=cF0>)
<a name="l103"></a> res+=</span><span class=cF5>DocOptEntry</span><span class=cF0>(doc,doc_e,fuf_flags);
<a name="l104"></a> </span><span class=cF1>if</span><span class=cF0> (doc_e_last &amp;&amp; doc_e_last-&gt;type&amp;~0xFF00==doc_e-&gt;type&amp;~0xFF00 &amp;&amp;
<a name="l105"></a> doc_e_last-&gt;de_flags==doc_e-&gt;de_flags &amp;&amp;
<a name="l106"></a> </span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cFB>doldoc</span><span class=cF0>.type_flags_chk_dup,doc_e-&gt;type_u8</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l107"></a> doc_e_last-&gt;attr==doc_e-&gt;attr) {
<a name="l108"></a> </span><span class=cF5>DocEntryDel</span><span class=cF0>(doc,doc_e);
<a name="l109"></a> res++;
<a name="l110"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l111"></a> doc_e_last=doc_e;
<a name="l112"></a> doc_e=doc_e1;
<a name="l113"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l114"></a> </span><span class=cF5>DocRecalc</span><span class=cF0>(doc);
<a name="l115"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l116"></a> </span><span class=cF5>DocUnlock</span><span class=cF0>(doc);
<a name="l117"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l118"></a>}
<a name="l119"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>DocOptFile</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *filename,</span><span class=cF9>I64</span><span class=cF0> fuf_flags)
<a name="l120"></a>{</span><span class=cF2>//Optimize file.</span><span class=cF0>
<a name="l121"></a> </span><span class=cF9>I64</span><span class=cF0> res;
<a name="l122"></a> </span><span class=cF9>CDoc</span><span class=cF0> *doc=</span><span class=cF5>DocRead</span><span class=cF0>(filename);
<a name="l123"></a> </span><span class=cF1>if</span><span class=cF0> (res=</span><span class=cF5>DocOptDoc</span><span class=cF7>(</span><span class=cF0>doc,fuf_flags</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l124"></a> </span><span class=cF6>&quot;-%d:%s\n&quot;</span><span class=cF0>,res,doc-&gt;filename.name;
<a name="l125"></a> </span><span class=cF5>DocWrite</span><span class=cF0>(doc);
<a name="l126"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l127"></a> </span><span class=cF5>DocDel</span><span class=cF0>(doc);
<a name="l128"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l129"></a>}
<a name="l130"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>DocOptLst</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0> *tmpde,</span><span class=cF9>I64</span><span class=cF0> fuf_flags)
<a name="l131"></a>{
<a name="l132"></a> </span><span class=cF9>I64</span><span class=cF0> res=0;
<a name="l133"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *tmpde1;
<a name="l134"></a> </span><span class=cF1>while</span><span class=cF0> (tmpde) </span><span class=cF7>{</span><span class=cF0>
<a name="l135"></a> tmpde1=tmpde-&gt;next;
<a name="l136"></a> </span><span class=cF1>if</span><span class=cF0> (tmpde-&gt;attr &amp; </span><span class=cF3>RS_ATTR_DIR</span><span class=cF0>) {
<a name="l137"></a> </span><span class=cF1>if</span><span class=cF0> (tmpde-&gt;sub) </span><span class=cF7>{</span><span class=cF0>
<a name="l138"></a> </span><span class=cF6>&quot;Scanning Directory: %s\n&quot;</span><span class=cF0>,tmpde-&gt;full_name;
<a name="l139"></a> res+=</span><span class=cF5>DocOptLst</span><span class=cF0>(tmpde-&gt;sub,fuf_flags);
<a name="l140"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l141"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l142"></a> res+=</span><span class=cF5>DocOptFile</span><span class=cF0>(tmpde-&gt;full_name,fuf_flags);
<a name="l143"></a> </span><span class=cF5>DirEntryDel</span><span class=cF0>(tmpde);
<a name="l144"></a> tmpde=tmpde1;
<a name="l145"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l146"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l147"></a>}
<a name="l148"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>DocOpt</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="l149"></a>{</span><span class=cF2>//Optimize </span><a href="/Wb/Doc/DolDocOverview.DD.HTML#l1"><span class=cF4>DolDoc</span></a><span class=cF2> files, eliminating aux_str's and .Z's.</span><span class=cF0>
<a name="l150"></a></span><span class=cF2>//+R flag for aggressively risky.</span><span class=cF0>
<a name="l151"></a> </span><span class=cF9>I64</span><span class=cF0> fuf_flags=0;
<a name="l152"></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+$&quot;</span><span class=cF0>);
<a name="l153"></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="l154"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>DocOptLst</span><span class=cF0>(</span><span class=cF5>FilesFind</span><span class=cF7>(</span><span class=cF0>files_find_mask,fuf_flags&amp;</span><span class=cF3>FUG_FILES_FIND</span><span class=cF7>)</span><span class=cF0>,
<a name="l155"></a> fuf_flags&amp;~</span><span class=cF3>FUG_FILES_FIND</span><span class=cF0>);
<a name="l156"></a>}
</span></pre></body>
</html>