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

172 lines
12 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=cF1>U0</span><span class=cF0> BgtDataRead()
<a name="l2"></a>{
<a name="l3"></a> CBgtEntry *tmpb;
<a name="l4"></a> CBgtTemplate *tmpt;
<a name="l5"></a> </span><span class=cF9>I64</span><span class=cF0> i,cnt,size;
<a name="l6"></a> </span><span class=cF1>U8</span><span class=cF0> *b,*ptr;
<a name="l7"></a> </span><span class=cF9>I64</span><span class=cF0> max_num;
<a name="l8"></a> </span><span class=cF1>U8</span><span class=cF0> **s=StrFileRead(bgt_string_file,&amp;max_num);
<a name="l9"></a>
<a name="l10"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&amp;b_head,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CBgtEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l11"></a> </span><span class=cF5>QueInit</span><span class=cF0>(&amp;b_head);
<a name="l12"></a> b_head.date=</span><span class=cF5>Now</span><span class=cF0>;
<a name="l13"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&amp;t_head,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CBgtTemplate</span><span class=cF7>)</span><span class=cF0>);
<a name="l14"></a> </span><span class=cF5>QueInit</span><span class=cF0>(&amp;t_head);
<a name="l15"></a> t_head.b.date=</span><span class=cF5>Now</span><span class=cF0>;
<a name="l16"></a>
<a name="l17"></a> </span><span class=cF1>if</span><span class=cF0> (ptr=b=</span><span class=cF5>FileRead</span><span class=cF7>(</span><span class=cF0>bgt_data_file,&amp;size</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l18"></a> cnt=*ptr(</span><span class=cF9>I64</span><span class=cF0> *)++;
<a name="l19"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;cnt;i++) {
<a name="l20"></a> tmpb=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CBgtEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l21"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&amp;tmpb-&gt;</span><span class=cF1>start</span><span class=cF0>,ptr,BE_SIZE);
<a name="l22"></a> tmpb-&gt;credit=</span><span class=cF5>StrNew</span><span class=cF0>(s[tmpb-&gt;credit_idx]);
<a name="l23"></a> tmpb-&gt;debit =</span><span class=cF5>StrNew</span><span class=cF0>(s[tmpb-&gt;debit_idx]);
<a name="l24"></a> tmpb-&gt;desc =</span><span class=cF5>StrNew</span><span class=cF0>(s[tmpb-&gt;desc_idx]);
<a name="l25"></a> </span><span class=cF5>QueIns</span><span class=cF0>(tmpb,b_head.last);
<a name="l26"></a> ptr+=BE_SIZE;
<a name="l27"></a> }
<a name="l28"></a>
<a name="l29"></a> cnt=*ptr(</span><span class=cF9>I64</span><span class=cF0> *)++;
<a name="l30"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;cnt;i++) {
<a name="l31"></a> tmpt=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CBgtTemplate</span><span class=cF7>)</span><span class=cF0>);
<a name="l32"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&amp;tmpt-&gt;</span><span class=cF1>start</span><span class=cF0>,ptr,BT_SIZE);
<a name="l33"></a> ptr+=BT_SIZE;
<a name="l34"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&amp;tmpt-&gt;b.</span><span class=cF1>start</span><span class=cF0>,ptr,BE_SIZE);
<a name="l35"></a> ptr+=BE_SIZE;
<a name="l36"></a> tmpt-&gt;b.credit=</span><span class=cF5>StrNew</span><span class=cF0>(s[tmpt-&gt;b.credit_idx]);
<a name="l37"></a> tmpt-&gt;b.debit =</span><span class=cF5>StrNew</span><span class=cF0>(s[tmpt-&gt;b.debit_idx]);
<a name="l38"></a> tmpt-&gt;b.desc =</span><span class=cF5>StrNew</span><span class=cF0>(s[tmpt-&gt;b.desc_idx]);
<a name="l39"></a> </span><span class=cF5>QueIns</span><span class=cF0>(tmpt,t_head.last);
<a name="l40"></a> }
<a name="l41"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l42"></a>
<a name="l43"></a> StrFileArrDel(s,max_num);
<a name="l44"></a> </span><span class=cF5>Free</span><span class=cF0>(b);
<a name="l45"></a>
<a name="l46"></a> BgtAcctsUpdate;
<a name="l47"></a>}
<a name="l48"></a>
<a name="l49"></a></span><span class=cF1>U0</span><span class=cF0> BgtDataWrite()
<a name="l50"></a>{
<a name="l51"></a> </span><span class=cF9>I64</span><span class=cF0> i,num=0,size,cnt1,cnt2;
<a name="l52"></a> </span><span class=cF9>CHashTable</span><span class=cF0> *table=</span><span class=cF5>HashTableNew</span><span class=cF0>(1024);
<a name="l53"></a> CBgtEntry *tmpb;
<a name="l54"></a> CBgtTemplate *tmpt;
<a name="l55"></a> </span><span class=cF9>CHashGeneric</span><span class=cF0> *tmph;
<a name="l56"></a> </span><span class=cF1>U8</span><span class=cF0> *buf,*ptr;
<a name="l57"></a>
<a name="l58"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;=accts_table-&gt;mask;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l59"></a> tmph=accts_table-&gt;body[i];
<a name="l60"></a> </span><span class=cF1>while</span><span class=cF0> (tmph) {
<a name="l61"></a> StrFileAdd(tmph-&gt;str,&amp;num,table); </span><span class=cF2>//Cosmetics -- make accts appear first.</span><span class=cF0>
<a name="l62"></a> tmph=tmph-&gt;next;
<a name="l63"></a> }
<a name="l64"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l65"></a>
<a name="l66"></a> tmpb=b_head.next;
<a name="l67"></a> cnt1=0;
<a name="l68"></a> </span><span class=cF1>while</span><span class=cF0> (tmpb!=&amp;b_head) </span><span class=cF7>{</span><span class=cF0>
<a name="l69"></a> </span><span class=cF1>if</span><span class=cF0> (tmpb-&gt;type!=BE_TEMPLATE_COPY) {
<a name="l70"></a> tmpb-&gt;credit_idx =StrFileAdd(tmpb-&gt;credit,&amp;num,table);
<a name="l71"></a> tmpb-&gt;debit_idx =StrFileAdd(tmpb-&gt;debit,&amp;num,table);
<a name="l72"></a> tmpb-&gt;desc_idx =StrFileAdd(tmpb-&gt;desc,&amp;num,table);
<a name="l73"></a> cnt1++;
<a name="l74"></a> }
<a name="l75"></a> tmpb=tmpb-&gt;next;
<a name="l76"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l77"></a>
<a name="l78"></a> tmpt=t_head.next;
<a name="l79"></a> cnt2=0;
<a name="l80"></a> </span><span class=cF1>while</span><span class=cF0> (tmpt!=&amp;t_head) </span><span class=cF7>{</span><span class=cF0>
<a name="l81"></a> tmpt-&gt;b.credit_idx =StrFileAdd(tmpt-&gt;b.credit,&amp;num,table);
<a name="l82"></a> tmpt-&gt;b.debit_idx =StrFileAdd(tmpt-&gt;b.debit,&amp;num,table);
<a name="l83"></a> tmpt-&gt;b.desc_idx =StrFileAdd(tmpt-&gt;b.desc,&amp;num,table);
<a name="l84"></a> cnt2++;
<a name="l85"></a> tmpt=tmpt-&gt;next;
<a name="l86"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l87"></a> StrFileWrite(bgt_string_file,table);
<a name="l88"></a> StrFileDel(table);
<a name="l89"></a>
<a name="l90"></a> size=</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0>)*2+cnt1*BE_SIZE+cnt2*(BT_SIZE+BE_SIZE);
<a name="l91"></a> buf=ptr=</span><span class=cF5>MAlloc</span><span class=cF0>(size);
<a name="l92"></a>
<a name="l93"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(ptr,&amp;cnt1,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>I64</span><span class=cF7>)</span><span class=cF0>);
<a name="l94"></a> ptr+=</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0>);
<a name="l95"></a> tmpb=b_head.next;
<a name="l96"></a> </span><span class=cF1>while</span><span class=cF0> (tmpb!=&amp;b_head) </span><span class=cF7>{</span><span class=cF0>
<a name="l97"></a> </span><span class=cF1>if</span><span class=cF0> (tmpb-&gt;type!=BE_TEMPLATE_COPY) {
<a name="l98"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(ptr,&amp;tmpb-&gt;</span><span class=cF1>start</span><span class=cF0>,BE_SIZE);
<a name="l99"></a> ptr+=BE_SIZE;
<a name="l100"></a> }
<a name="l101"></a> tmpb=tmpb-&gt;next;
<a name="l102"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l103"></a>
<a name="l104"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(ptr,&amp;cnt2,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>I64</span><span class=cF7>)</span><span class=cF0>);
<a name="l105"></a> ptr+=</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0>);
<a name="l106"></a> tmpt=t_head.next;
<a name="l107"></a> </span><span class=cF1>while</span><span class=cF0> (tmpt!=&amp;t_head) </span><span class=cF7>{</span><span class=cF0>
<a name="l108"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(ptr,&amp;tmpt-&gt;</span><span class=cF1>start</span><span class=cF0>,BT_SIZE);
<a name="l109"></a> ptr+=BT_SIZE;
<a name="l110"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(ptr,&amp;tmpt-&gt;b.</span><span class=cF1>start</span><span class=cF0>,BE_SIZE);
<a name="l111"></a> ptr+=BE_SIZE;
<a name="l112"></a> tmpt=tmpt-&gt;next;
<a name="l113"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l114"></a>
<a name="l115"></a> </span><span class=cF5>FileWrite</span><span class=cF0>(bgt_data_file,buf,size);
<a name="l116"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l117"></a>}
<a name="l118"></a>
<a name="l119"></a></span><span class=cF1>U0</span><span class=cF0> BgtDel()
<a name="l120"></a>{
<a name="l121"></a> CBgtEntry *tmpb,*tmpb1;
<a name="l122"></a> CBgtTemplate *tmpt,*tmpt1;
<a name="l123"></a> tmpb=b_head.next;
<a name="l124"></a> </span><span class=cF1>while</span><span class=cF0> (tmpb!=&amp;b_head) </span><span class=cF7>{</span><span class=cF0>
<a name="l125"></a> tmpb1=tmpb-&gt;next;
<a name="l126"></a> BgtEntryDel2(tmpb);
<a name="l127"></a> </span><span class=cF5>Free</span><span class=cF0>(tmpb);
<a name="l128"></a> tmpb=tmpb1;
<a name="l129"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l130"></a> tmpt=t_head.next;
<a name="l131"></a> </span><span class=cF1>while</span><span class=cF0> (tmpt!=&amp;t_head) </span><span class=cF7>{</span><span class=cF0>
<a name="l132"></a> tmpt1=tmpt-&gt;next;
<a name="l133"></a> BgtEntryDel2(&amp;tmpt-&gt;b);
<a name="l134"></a> </span><span class=cF5>Free</span><span class=cF0>(tmpt);
<a name="l135"></a> tmpt=tmpt1;
<a name="l136"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l137"></a> StrFileDel(accts_table);
<a name="l138"></a> accts_table=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l139"></a> accts_table_strs=0;
<a name="l140"></a>}
</span></pre></body>
</html>