150 lines
15 KiB
HTML
Executable File
150 lines
15 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>U8</span><span class=cF0> *</span><span class=cF5>FileRead</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *filename,</span><span class=cF9>I64</span><span class=cF0> *_size=</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF9>I64</span><span class=cF0> *_attr=</span><span class=cF3>NULL</span><span class=cF0>)
|
|
<a name="l2"></a>{</span><span class=cF2>//Read whole file from disk.</span><span class=cF0>
|
|
<a name="l3"></a> </span><span class=cF9>CHashGeneric</span><span class=cF0> *tmph;
|
|
<a name="l4"></a> </span><span class=cF1>U8</span><span class=cF0> *absname,*altname,*curname,*res=</span><span class=cF3>NULL</span><span class=cF0>;
|
|
<a name="l5"></a> </span><span class=cF9>I64</span><span class=cF0> i,size=0,attr=0;
|
|
<a name="l6"></a> </span><span class=cF9>CDirContext</span><span class=cF0> *dirc;
|
|
<a name="l7"></a> </span><span class=cF9>CArcCompress</span><span class=cF0> *arc;
|
|
<a name="l8"></a> absname=</span><span class=cF5>FileNameAbs</span><span class=cF0>(filename);
|
|
<a name="l9"></a> altname=</span><span class=cF5>ToggleZorNotZ</span><span class=cF0>(absname);
|
|
<a name="l10"></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>(absname,</span><span class=cFB>adam_task</span><span class=cF0>->hash_table,</span><span class=cF3>HTT_FILE</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0>||
|
|
<a name="l11"></a> </span><span class=cF7>(</span><span class=cF0>tmph=</span><span class=cF5>HashFind</span><span class=cF0>(altname,</span><span class=cFB>adam_task</span><span class=cF0>->hash_table,</span><span class=cF3>HTT_FILE</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l12"></a> size=tmph->user_data1;
|
|
<a name="l13"></a> res=</span><span class=cF5>MAlloc</span><span class=cF0>(size+1);
|
|
<a name="l14"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(res,tmph->user_data0,size);
|
|
<a name="l15"></a> res[size]=0; </span><span class=cF2>//Terminate</span><span class=cF0>
|
|
<a name="l16"></a> attr=</span><span class=cF5>FileAttr</span><span class=cF0>(tmph->str,attr);
|
|
<a name="l17"></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="l18"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<2 && !res;i++) {</span><span class=cF2>//Try name, then altname</span><span class=cF0>
|
|
<a name="l19"></a> </span><span class=cF1>if</span><span class=cF0> (!i)
|
|
<a name="l20"></a> curname=absname;
|
|
<a name="l21"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l22"></a> curname=altname;
|
|
<a name="l23"></a> </span><span class=cF1>if</span><span class=cF0> (dirc=</span><span class=cF5>DirContextNew</span><span class=cF7>(</span><span class=cF0>curname</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l24"></a> </span><span class=cF1>switch</span><span class=cF0> (dirc->dv->fs_type) {
|
|
<a name="l25"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
|
|
<a name="l26"></a> res=</span><span class=cFD>RedSeaFileRead</span><span class=cF0>(dirc->dv,</span><span class=cF5>Fs</span><span class=cF0>->cur_dir,dirc->mask,&size,&attr);
|
|
<a name="l27"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l28"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
|
|
<a name="l29"></a> res=</span><span class=cFD>FAT32FileRead</span><span class=cF0>(dirc->dv,</span><span class=cF5>Fs</span><span class=cF0>->cur_dir,dirc->mask,&size,&attr);
|
|
<a name="l30"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l31"></a> </span><span class=cF1>default</span><span class=cF0>:
|
|
<a name="l32"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"File System Not Supported\n"</span><span class=cF0>);
|
|
<a name="l33"></a> }
|
|
<a name="l34"></a> </span><span class=cF5>DirContextDel</span><span class=cF0>(dirc);
|
|
<a name="l35"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l36"></a> }
|
|
<a name="l37"></a>
|
|
<a name="l38"></a> </span><span class=cF2>//Search parent directories.</span><span class=cF0>
|
|
<a name="l39"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<2 && !res;i++) {</span><span class=cF2>//Try name, then altname</span><span class=cF0>
|
|
<a name="l40"></a> </span><span class=cF1>if</span><span class=cF0> (!i)
|
|
<a name="l41"></a> curname=absname;
|
|
<a name="l42"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l43"></a> curname=altname;
|
|
<a name="l44"></a> </span><span class=cF1>if</span><span class=cF0> (dirc=</span><span class=cF5>DirContextNew</span><span class=cF7>(</span><span class=cF0>curname</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l45"></a> </span><span class=cF1>while</span><span class=cF0> (!res && </span><span class=cF5>StrCmp</span><span class=cF7>(</span><span class=cF5>Fs</span><span class=cF0>->cur_dir,</span><span class=cF6>"/"</span><span class=cF7>)</span><span class=cF0>) {
|
|
<a name="l46"></a> </span><span class=cF5>Cd</span><span class=cF0>(</span><span class=cF6>".."</span><span class=cF0>);
|
|
<a name="l47"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>Fs</span><span class=cF0>->cur_dv->fs_type) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l48"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
|
|
<a name="l49"></a> res=</span><span class=cFD>RedSeaFileRead</span><span class=cF0>(dirc->dv,</span><span class=cF5>Fs</span><span class=cF0>->cur_dir,dirc->mask,&size,&attr);
|
|
<a name="l50"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l51"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
|
|
<a name="l52"></a> res=</span><span class=cFD>FAT32FileRead</span><span class=cF0>(dirc->dv,</span><span class=cF5>Fs</span><span class=cF0>->cur_dir,dirc->mask,&size,&attr);
|
|
<a name="l53"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l54"></a> </span><span class=cF1>default</span><span class=cF0>:
|
|
<a name="l55"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"File System Not Supported\n"</span><span class=cF0>);
|
|
<a name="l56"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l57"></a> }
|
|
<a name="l58"></a> </span><span class=cF5>DirContextDel</span><span class=cF0>(dirc);
|
|
<a name="l59"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l60"></a> }
|
|
<a name="l61"></a> </span><span class=cF1>if</span><span class=cF0> (!res)
|
|
<a name="l62"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"File not found: \"%s\".\n"</span><span class=cF0>,filename);
|
|
<a name="l63"></a> </span><span class=cF1>if</span><span class=cF0> (res && attr & </span><span class=cF3>RS_ATTR_RESIDENT</span><span class=cF0>)
|
|
<a name="l64"></a> </span><span class=cF5>HashGenericAdd</span><span class=cF0>(curname,</span><span class=cF3>HTT_FILE</span><span class=cF0>,</span><span class=cF5>AMAllocIdent</span><span class=cF7>(</span><span class=cF0>res</span><span class=cF7>)</span><span class=cF0>,size,0,</span><span class=cFB>adam_task</span><span class=cF0>);
|
|
<a name="l65"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l66"></a> </span><span class=cF1>if</span><span class=cF0> (res && attr & </span><span class=cF3>RS_ATTR_COMPRESSED</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l67"></a> arc=res;
|
|
<a name="l68"></a> size=arc->expanded_size;
|
|
<a name="l69"></a> res=</span><span class=cF5>ExpandBuf</span><span class=cF0>(arc);
|
|
<a name="l70"></a> </span><span class=cF5>Free</span><span class=cF0>(arc);
|
|
<a name="l71"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l72"></a> </span><span class=cF1>if</span><span class=cF0> (_attr) *_attr=attr;
|
|
<a name="l73"></a> </span><span class=cF1>if</span><span class=cF0> (_size) *_size=size;
|
|
<a name="l74"></a> </span><span class=cF5>Free</span><span class=cF0>(absname);
|
|
<a name="l75"></a> </span><span class=cF5>Free</span><span class=cF0>(altname);
|
|
<a name="l76"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
|
<a name="l77"></a>}
|
|
<a name="l78"></a>
|
|
<a name="l79"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>FileWrite</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *filename,</span><span class=cF1>U8</span><span class=cF0> *fbuf,</span><span class=cF9>I64</span><span class=cF0> size,</span><span class=cF9>CDate</span><span class=cF0> cdt=0,</span><span class=cF9>I64</span><span class=cF0> attr=0)
|
|
<a name="l80"></a>{</span><span class=cF2>//Write whole file to disk.</span><span class=cF0>
|
|
<a name="l81"></a> </span><span class=cF9>I64</span><span class=cF0> c=0;
|
|
<a name="l82"></a> </span><span class=cF9>CHashGeneric</span><span class=cF0> *tmph;
|
|
<a name="l83"></a> </span><span class=cF9>CDirContext</span><span class=cF0> *dirc;
|
|
<a name="l84"></a> </span><span class=cF1>U8</span><span class=cF0> *fbuf2,*absname=</span><span class=cF5>FileNameAbs</span><span class=cF0>(filename);
|
|
<a name="l85"></a> </span><span class=cF1>if</span><span class=cF0> (dirc=</span><span class=cF5>DirContextNew</span><span class=cF7>(</span><span class=cF0>filename,</span><span class=cF3>FALSE</span><span class=cF0>,</span><span class=cF3>TRUE</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l86"></a> attr=</span><span class=cF5>FileAttr</span><span class=cF0>(dirc->mask,attr);
|
|
<a name="l87"></a> </span><span class=cF1>if</span><span class=cF0> (attr&</span><span class=cF3>RS_ATTR_COMPRESSED</span><span class=cF0>) {
|
|
<a name="l88"></a> fbuf=</span><span class=cF5>CompressBuf</span><span class=cF0>(fbuf,size);
|
|
<a name="l89"></a> size=fbuf(</span><span class=cF9>CArcCompress</span><span class=cF0> *)->compressed_size;
|
|
<a name="l90"></a> fbuf2=fbuf;
|
|
<a name="l91"></a> } </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l92"></a> fbuf2=</span><span class=cF3>NULL</span><span class=cF0>;
|
|
<a name="l93"></a> </span><span class=cF1>if</span><span class=cF0> (!cdt) cdt=</span><span class=cF5>Now</span><span class=cF0>;
|
|
<a name="l94"></a> </span><span class=cF1>switch</span><span class=cF0> (dirc->dv->fs_type) {
|
|
<a name="l95"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
|
|
<a name="l96"></a> c=</span><span class=cFD>RedSeaFileWrite</span><span class=cF0>(dirc->dv,</span><span class=cF5>Fs</span><span class=cF0>->cur_dir,dirc->mask,fbuf,size,cdt,attr);
|
|
<a name="l97"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l98"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
|
|
<a name="l99"></a> c=</span><span class=cFD>FAT32FileWrite</span><span class=cF0>(dirc->dv,</span><span class=cF5>Fs</span><span class=cF0>->cur_dir,dirc->mask,fbuf,size,cdt,attr);
|
|
<a name="l100"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l101"></a> </span><span class=cF1>default</span><span class=cF0>:
|
|
<a name="l102"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"File System Not Supported\n"</span><span class=cF0>);
|
|
<a name="l103"></a> }
|
|
<a name="l104"></a> </span><span class=cF1>if</span><span class=cF0> (tmph=</span><span class=cF5>HashFind</span><span class=cF7>(</span><span class=cF0>absname,</span><span class=cFB>adam_task</span><span class=cF0>->hash_table,</span><span class=cF3>HTT_FILE</span><span class=cF7>)</span><span class=cF0>) {
|
|
<a name="l105"></a> </span><span class=cF1>if</span><span class=cF0> (attr & </span><span class=cF3>RS_ATTR_RESIDENT</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l106"></a> </span><span class=cF5>Free</span><span class=cF0>(tmph->user_data0);
|
|
<a name="l107"></a> tmph->user_data0=</span><span class=cF5>AMAllocIdent</span><span class=cF0>(fbuf);
|
|
<a name="l108"></a> tmph->user_data1=size;
|
|
<a name="l109"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l110"></a> </span><span class=cF5>HashRemDel</span><span class=cF0>(tmph,</span><span class=cFB>adam_task</span><span class=cF0>->hash_table);
|
|
<a name="l111"></a> } </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (attr & </span><span class=cF3>RS_ATTR_RESIDENT</span><span class=cF0>)
|
|
<a name="l112"></a> </span><span class=cF5>HashGenericAdd</span><span class=cF0>(absname,</span><span class=cF3>HTT_FILE</span><span class=cF0>,</span><span class=cF5>AMAllocIdent</span><span class=cF7>(</span><span class=cF0>fbuf</span><span class=cF7>)</span><span class=cF0>,size,0,</span><span class=cFB>adam_task</span><span class=cF0>);
|
|
<a name="l113"></a> </span><span class=cF5>Free</span><span class=cF0>(fbuf2);
|
|
<a name="l114"></a> </span><span class=cF5>DirContextDel</span><span class=cF0>(dirc);
|
|
<a name="l115"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l116"></a> </span><span class=cF5>Free</span><span class=cF0>(absname);
|
|
<a name="l117"></a> </span><span class=cF1>return</span><span class=cF0> c;
|
|
<a name="l118"></a>}
|
|
</span></pre></body>
|
|
</html>
|