templeos-info/public/Wb/Apps/Budget/BgtStrs.HC.HTML

164 lines
13 KiB
Plaintext
Raw Normal View History

2024-03-24 21:24:44 +00:00
<!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>define</span><span class=cF0> SFT_GENERIC 1
<a name="l2"></a>
<a name="l3"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U8</span><span class=cF0> **StrFileRead(</span><span class=cF1>U8</span><span class=cF0> *name,</span><span class=cF9>I64</span><span class=cF0> *_max_num=</span><span class=cF3>NULL</span><span class=cF0>,
<a name="l4"></a> </span><span class=cF1>U8</span><span class=cF0> **_colors=</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF1>Bool</span><span class=cF0> no_nums=</span><span class=cF3>FALSE</span><span class=cF0>)
<a name="l5"></a>{
<a name="l6"></a> </span><span class=cF9>CDoc</span><span class=cF0> *doc=</span><span class=cF5>DocRead</span><span class=cF0>(name,</span><span class=cF3>DOCF_DBL_DOLLARS</span><span class=cF0>|</span><span class=cF3>DOCF_NO_CURSOR</span><span class=cF0>);
<a name="l7"></a> </span><span class=cF9>CDocEntry</span><span class=cF0> *doc_e=doc-&gt;head.next;
<a name="l8"></a> </span><span class=cF9>I64</span><span class=cF0> i,max_num=0;
<a name="l9"></a> </span><span class=cF1>U8</span><span class=cF0> *ptr,**res,*colors;
<a name="l10"></a>
<a name="l11"></a> </span><span class=cF1>while</span><span class=cF0> (doc_e!=doc) </span><span class=cF7>{</span><span class=cF0>
<a name="l12"></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="l13"></a> </span><span class=cF1>if</span><span class=cF0> (no_nums)
<a name="l14"></a> i=++max_num;
<a name="l15"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l16"></a> i=</span><span class=cF5>Str2I64</span><span class=cF0>(doc_e-&gt;tag,,&amp;ptr);
<a name="l17"></a> </span><span class=cF1>if</span><span class=cF0> (i&gt;max_num) max_num=i;
<a name="l18"></a> </span><span class=cF1>if</span><span class=cF0> (*ptr==</span><span class=cF6>','</span><span class=cF0>) ptr++;
<a name="l19"></a> ptr=</span><span class=cF5>StrNew</span><span class=cF0>(ptr);
<a name="l20"></a> </span><span class=cF5>Free</span><span class=cF0>(doc_e-&gt;tag);
<a name="l21"></a> doc_e-&gt;tag=ptr;
<a name="l22"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l23"></a> doc_e-&gt;user_data=i;
<a name="l24"></a> }
<a name="l25"></a> doc_e=doc_e-&gt;next;
<a name="l26"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l27"></a>
<a name="l28"></a> res=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF7>(</span><span class=cF0>max_num+1</span><span class=cF7>)</span><span class=cF0>);
<a name="l29"></a> colors=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF7>(</span><span class=cF0>max_num+1</span><span class=cF7>)</span><span class=cF0>);
<a name="l30"></a> doc_e=doc-&gt;head.next;
<a name="l31"></a> </span><span class=cF1>while</span><span class=cF0> (doc_e!=doc) </span><span class=cF7>{</span><span class=cF0>
<a name="l32"></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> &amp;&amp; 0&lt;=doc_e-&gt;user_data&lt;=max_num) {
<a name="l33"></a> res[doc_e-&gt;user_data]=doc_e-&gt;tag;
<a name="l34"></a> doc_e-&gt;tag=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l35"></a> colors[doc_e-&gt;user_data]=doc_e-&gt;type.u8[1]&amp;15;
<a name="l36"></a> }
<a name="l37"></a> doc_e=doc_e-&gt;next;
<a name="l38"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l39"></a>
<a name="l40"></a> </span><span class=cF5>DocDel</span><span class=cF0>(doc);
<a name="l41"></a> </span><span class=cF1>if</span><span class=cF0> (_max_num) *_max_num=max_num;
<a name="l42"></a> </span><span class=cF1>if</span><span class=cF0> (_colors)
<a name="l43"></a> *_colors=colors;
<a name="l44"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l45"></a> </span><span class=cF5>Free</span><span class=cF0>(colors);
<a name="l46"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l47"></a>}
<a name="l48"></a>
<a name="l49"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> StrFileArrDel(</span><span class=cF1>U8</span><span class=cF0> **a,</span><span class=cF9>I64</span><span class=cF0> max_num)
<a name="l50"></a>{
<a name="l51"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l52"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;=max_num;i++)
<a name="l53"></a> </span><span class=cF5>Free</span><span class=cF0>(a[i]);
<a name="l54"></a> </span><span class=cF5>Free</span><span class=cF0>(a);
<a name="l55"></a>}
<a name="l56"></a>
<a name="l57"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> StrFileAdd(</span><span class=cF1>U8</span><span class=cF0> *st,</span><span class=cF9>I64</span><span class=cF0> *_num,
<a name="l58"></a> </span><span class=cF9>CHashTable</span><span class=cF0> *table,</span><span class=cF9>I64</span><span class=cF0> color=</span><span class=cF3>COLOR_INVALID</span><span class=cF0>)
<a name="l59"></a>{
<a name="l60"></a> </span><span class=cF9>CHashGeneric</span><span class=cF0> *tmph;
<a name="l61"></a> </span><span class=cF1>if</span><span class=cF0> (!st) </span><span class=cF1>return</span><span class=cF0> 0;
<a name="l62"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>tmph=</span><span class=cF5>HashFind</span><span class=cF0>(st,table,SFT_GENERIC)</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l63"></a> tmph=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CHashGeneric</span><span class=cF7>)</span><span class=cF0>);
<a name="l64"></a> tmph-&gt;type=SFT_GENERIC;
<a name="l65"></a> tmph-&gt;str=</span><span class=cF5>StrNew</span><span class=cF0>(st);
<a name="l66"></a> tmph-&gt;user_data0=(*_num)++;
<a name="l67"></a> </span><span class=cF5>HashAdd</span><span class=cF0>(tmph,table);
<a name="l68"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l69"></a> </span><span class=cF1>if</span><span class=cF0> (color!=</span><span class=cF3>COLOR_INVALID</span><span class=cF0>)
<a name="l70"></a> tmph-&gt;user_data1=color;
<a name="l71"></a> </span><span class=cF1>return</span><span class=cF0> tmph-&gt;user_data0;
<a name="l72"></a>}
<a name="l73"></a>
<a name="l74"></a></span><span class=cF9>I64</span><span class=cF0> StrEntriesCompare(</span><span class=cF9>CHashGeneric</span><span class=cF0> *h1,</span><span class=cF9>CHashGeneric</span><span class=cF0> *h2)
<a name="l75"></a>{
<a name="l76"></a> </span><span class=cF1>return</span><span class=cF0> h1-&gt;user_data0-h2-&gt;user_data0;
<a name="l77"></a>}
<a name="l78"></a>
<a name="l79"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> StrFileWrite(</span><span class=cF1>U8</span><span class=cF0> *name,</span><span class=cF9>CHashTable</span><span class=cF0> *table,</span><span class=cF1>Bool</span><span class=cF0> no_nums=</span><span class=cF3>FALSE</span><span class=cF0>)
<a name="l80"></a>{
<a name="l81"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,cnt,color=</span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l82"></a> </span><span class=cF9>CDoc</span><span class=cF0> *doc=</span><span class=cF5>DocNew</span><span class=cF0>(name);
<a name="l83"></a> </span><span class=cF9>CHashGeneric</span><span class=cF0> *tmph,**a;
<a name="l84"></a> </span><span class=cF1>if</span><span class=cF0> (table) </span><span class=cF7>{</span><span class=cF0>
<a name="l85"></a> cnt=0; </span><span class=cF2>//Count Strings</span><span class=cF0>
<a name="l86"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;=table-&gt;mask;i++)
<a name="l87"></a> cnt+=</span><span class=cF5>LinkedLstCnt</span><span class=cF0>(table-&gt;body[i]);
<a name="l88"></a> a=</span><span class=cF5>MAlloc</span><span class=cF0>(cnt*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CHashGeneric</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>);
<a name="l89"></a> j=0; </span><span class=cF2>//Load Strings</span><span class=cF0>
<a name="l90"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;=table-&gt;mask;i++) {
<a name="l91"></a> tmph=table-&gt;body[i];
<a name="l92"></a> </span><span class=cF1>while</span><span class=cF0> (tmph) </span><span class=cF7>{</span><span class=cF0>
<a name="l93"></a> a[j++]=tmph;
<a name="l94"></a> tmph=tmph-&gt;next;
<a name="l95"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l96"></a> }
<a name="l97"></a> </span><span class=cF5>QSortI64</span><span class=cF0>(a,cnt,&amp;StrEntriesCompare);
<a name="l98"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;cnt;i++) {
<a name="l99"></a> tmph=a[i];
<a name="l100"></a> </span><span class=cF1>if</span><span class=cF0> (tmph-&gt;user_data1&amp;15!=color) </span><span class=cF7>{</span><span class=cF0>
<a name="l101"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc,</span><span class=cF6>&quot;$FG,%d$&quot;</span><span class=cF0>,tmph-&gt;user_data1&amp;15);
<a name="l102"></a> color=tmph-&gt;user_data1&amp;15;
<a name="l103"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l104"></a> </span><span class=cF1>if</span><span class=cF0> (no_nums)
<a name="l105"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc,</span><span class=cF6>&quot;%s\n&quot;</span><span class=cF0>,tmph-&gt;str);
<a name="l106"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l107"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc,</span><span class=cF6>&quot;%d,%s\n&quot;</span><span class=cF0>,tmph-&gt;user_data0,tmph-&gt;str);
<a name="l108"></a> }
<a name="l109"></a> </span><span class=cF5>Free</span><span class=cF0>(a);
<a name="l110"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l111"></a> doc-&gt;flags|=</span><span class=cF3>DOCF_NO_CURSOR</span><span class=cF0>;
<a name="l112"></a> </span><span class=cF5>DocWrite</span><span class=cF0>(doc);
<a name="l113"></a> </span><span class=cF5>DocDel</span><span class=cF0>(doc);
<a name="l114"></a>}
<a name="l115"></a>
<a name="l116"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> StrFileDel(</span><span class=cF9>CHashTable</span><span class=cF0> *table)
<a name="l117"></a>{
<a name="l118"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l119"></a> </span><span class=cF9>CHashGeneric</span><span class=cF0> *tmph,*tmph1;
<a name="l120"></a> </span><span class=cF1>if</span><span class=cF0> (!table) </span><span class=cF1>return</span><span class=cF0>;
<a name="l121"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;=table-&gt;mask;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l122"></a> tmph=table-&gt;body[i];
<a name="l123"></a> </span><span class=cF1>while</span><span class=cF0> (tmph) {
<a name="l124"></a> tmph1=tmph-&gt;next;
<a name="l125"></a> </span><span class=cF5>Free</span><span class=cF0>(tmph-&gt;str);
<a name="l126"></a> </span><span class=cF5>Free</span><span class=cF0>(tmph);
<a name="l127"></a> tmph=tmph1;
<a name="l128"></a> }
<a name="l129"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l130"></a> </span><span class=cF5>Free</span><span class=cF0>(table-&gt;body);
<a name="l131"></a> </span><span class=cF5>Free</span><span class=cF0>(table);
<a name="l132"></a>}
</span></pre></body>
</html>