templeos-info/public/Wb/Kernel/BlkDev/DskDirContext.HC.HTML

119 lines
12 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=cF1>U0</span><span class=cF0> </span><span class=cF5>DirContextDel</span><span class=cF0>(</span><span class=cF9>CDirContext</span><span class=cF0> *dirc,</span><span class=cF1>Bool</span><span class=cF0> restore=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l2"></a>{</span><span class=cF2>//Change back to old cur_dir and drv.</span><span class=cF0>
<a name="l3"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd;
<a name="l4"></a> </span><span class=cF1>if</span><span class=cF0> (!dirc) </span><span class=cF1>return</span><span class=cF0>;
<a name="l5"></a> </span><span class=cF1>if</span><span class=cF0> (restore) </span><span class=cF7>{</span><span class=cF0>
<a name="l6"></a> bd=dirc-&gt;old_dv-&gt;bd;
<a name="l7"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>bd-&gt;flags &amp; </span><span class=cF3>BDF_INIT_IN_PROGRESS</span><span class=cF7>)</span><span class=cF0>) {
<a name="l8"></a> </span><span class=cF1>if</span><span class=cF0> (dirc-&gt;old_dir) </span><span class=cF7>{</span><span class=cF0>
<a name="l9"></a> </span><span class=cF5>Drv</span><span class=cF0>(</span><span class=cF5>Drv2Let</span><span class=cF7>(</span><span class=cF0>dirc-&gt;old_dv</span><span class=cF7>)</span><span class=cF0>);
<a name="l10"></a> </span><span class=cF5>Cd</span><span class=cF0>(dirc-&gt;old_dir);
<a name="l11"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l12"></a> } </span><span class=cF1>else</span><span class=cF0> {
<a name="l13"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv=dirc-&gt;old_dv;
<a name="l14"></a> </span><span class=cF5>Free</span><span class=cF0>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir);
<a name="l15"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir=</span><span class=cF5>StrNew</span><span class=cF0>(</span><span class=cF6>&quot;/&quot;</span><span class=cF0>);
<a name="l16"></a> }
<a name="l17"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l18"></a> </span><span class=cF5>Free</span><span class=cF0>(dirc-&gt;old_dir);
<a name="l19"></a> </span><span class=cF5>Free</span><span class=cF0>(dirc-&gt;mask);
<a name="l20"></a> </span><span class=cF5>Free</span><span class=cF0>(dirc);
<a name="l21"></a>}
<a name="l22"></a>
<a name="l23"></a></span><span class=cF9>CDirContext</span><span class=cF0> *</span><span class=cF5>DirContextNew</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *_mask,</span><span class=cF1>Bool</span><span class=cF0> make_mask=</span><span class=cF3>FALSE</span><span class=cF0>,
<a name="l24"></a> </span><span class=cF1>Bool</span><span class=cF0> make_dirs=</span><span class=cF3>FALSE</span><span class=cF0>,</span><span class=cF1>Bool</span><span class=cF0> no_mask=</span><span class=cF3>FALSE</span><span class=cF0>)
<a name="l25"></a>{</span><span class=cF2>//Save cur_dir and drv. Change to new dir.</span><span class=cF0>
<a name="l26"></a> </span><span class=cF1>Bool</span><span class=cF0> valid=</span><span class=cF3>TRUE</span><span class=cF0>,old_silent;
<a name="l27"></a> </span><span class=cF9>I64</span><span class=cF0> mask_len=</span><span class=cF5>StrLen</span><span class=cF0>(_mask);
<a name="l28"></a> </span><span class=cF1>U8</span><span class=cF0> *buf,*mask,*tmp_mask,*semicolon_mask;
<a name="l29"></a> </span><span class=cF9>CDirContext</span><span class=cF0> *dirc=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDirContext</span><span class=cF7>)</span><span class=cF0>);
<a name="l30"></a> dirc-&gt;old_dir=</span><span class=cF5>StrNew</span><span class=cF0>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir);
<a name="l31"></a> dirc-&gt;old_dv=</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv;
<a name="l32"></a> mask=</span><span class=cF5>MStrUtil</span><span class=cF0>(_mask,</span><span class=cF3>SUF_REM_LEADING</span><span class=cF0>|</span><span class=cF3>SUF_REM_TRAILING</span><span class=cF0>|</span><span class=cF3>SUF_REM_CTRL_CHARS</span><span class=cF0>);
<a name="l33"></a> tmp_mask=mask;
<a name="l34"></a> </span><span class=cF1>if</span><span class=cF0> (*mask &amp;&amp; mask[1]==</span><span class=cF6>':'</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l35"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv!=</span><span class=cF5>Let2Drv</span><span class=cF7>(</span><span class=cF0>*mask</span><span class=cF7>)</span><span class=cF0> &amp;&amp; !</span><span class=cF5>Drv</span><span class=cF7>(</span><span class=cF0>*mask</span><span class=cF7>)</span><span class=cF0>)
<a name="l36"></a> valid=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l37"></a> mask+=2;
<a name="l38"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l39"></a> </span><span class=cF1>if</span><span class=cF0> (*mask==</span><span class=cF6>'~'</span><span class=cF0> &amp;&amp; </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv!=</span><span class=cF5>Let2Drv</span><span class=cF7>(</span><span class=cF6>'~'</span><span class=cF7>)</span><span class=cF0> &amp;&amp; !</span><span class=cF5>Drv</span><span class=cF7>(</span><span class=cF6>'~'</span><span class=cF7>)</span><span class=cF0>)
<a name="l40"></a> valid=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l41"></a> dirc-&gt;dv=</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv;
<a name="l42"></a> </span><span class=cF5>DrvChk</span><span class=cF0>(dirc-&gt;dv);
<a name="l43"></a> buf=</span><span class=cF5>MAlloc</span><span class=cF0>(mask_len+2);
<a name="l44"></a> </span><span class=cF5>StrCpy</span><span class=cF0>(buf,mask);
<a name="l45"></a>
<a name="l46"></a> dirc-&gt;mask=</span><span class=cF5>MAlloc</span><span class=cF0>(mask_len+2);
<a name="l47"></a> </span><span class=cF1>if</span><span class=cF0> (no_mask)
<a name="l48"></a> *dirc-&gt;mask=0;
<a name="l49"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrOcc</span><span class=cF7>(</span><span class=cF0>buf,</span><span class=cF6>';'</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l50"></a> semicolon_mask=</span><span class=cF5>MAlloc</span><span class=cF0>(mask_len+2);
<a name="l51"></a> </span><span class=cF5>StrCpy</span><span class=cF0>(semicolon_mask,mask);
<a name="l52"></a> </span><span class=cF5>StrFirstRem</span><span class=cF0>(semicolon_mask,</span><span class=cF6>&quot;;&quot;</span><span class=cF0>,buf);
<a name="l53"></a> </span><span class=cF5>StrLastRem</span><span class=cF0>(buf,</span><span class=cF6>&quot;/&quot;</span><span class=cF0>,dirc-&gt;mask);
<a name="l54"></a> </span><span class=cF5>CatPrint</span><span class=cF0>(dirc-&gt;mask,</span><span class=cF6>&quot;;%s&quot;</span><span class=cF0>,semicolon_mask);
<a name="l55"></a> </span><span class=cF5>Free</span><span class=cF0>(semicolon_mask);
<a name="l56"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l57"></a> </span><span class=cF5>StrLastRem</span><span class=cF0>(buf,</span><span class=cF6>&quot;/&quot;</span><span class=cF0>,dirc-&gt;mask);
<a name="l58"></a>
<a name="l59"></a> </span><span class=cF1>if</span><span class=cF0> (*mask==</span><span class=cF6>'/'</span><span class=cF0> &amp;&amp; !*buf)
<a name="l60"></a> </span><span class=cF5>StrCpy</span><span class=cF0>(buf,</span><span class=cF6>&quot;/&quot;</span><span class=cF0>);
<a name="l61"></a></span><span class=cF2>//If began with Dir, change to Dir.</span><span class=cF0>
<a name="l62"></a> </span><span class=cF1>if</span><span class=cF0> (*buf &amp;&amp; !</span><span class=cF5>Cd</span><span class=cF7>(</span><span class=cF0>buf,make_dirs</span><span class=cF7>)</span><span class=cF0>)
<a name="l63"></a> valid=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l64"></a> </span><span class=cF1>if</span><span class=cF0> (valid &amp;&amp; make_mask) </span><span class=cF7>{</span><span class=cF0>
<a name="l65"></a> </span><span class=cF1>if</span><span class=cF0> (!*dirc-&gt;mask) {
<a name="l66"></a> </span><span class=cF5>Free</span><span class=cF0>(dirc-&gt;mask);
<a name="l67"></a> dirc-&gt;mask=</span><span class=cF5>StrNew</span><span class=cF0>(</span><span class=cF6>&quot;*&quot;</span><span class=cF0>);
<a name="l68"></a> } </span><span class=cF1>else</span><span class=cF0> {
<a name="l69"></a> </span><span class=cF1>if</span><span class=cF0> (!make_dirs || </span><span class=cF5>FileNameChk</span><span class=cF7>(</span><span class=cF0>dirc-&gt;mask</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l70"></a> old_silent=</span><span class=cF5>Silent</span><span class=cF0>;
<a name="l71"></a></span><span class=cF2>//Try mask to see if Dir. If Dir, change to dir and set to &quot;*&quot;.</span><span class=cF0>
<a name="l72"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Cd</span><span class=cF7>(</span><span class=cF0>dirc-&gt;mask,make_dirs</span><span class=cF7>)</span><span class=cF0>) {
<a name="l73"></a> </span><span class=cF5>Free</span><span class=cF0>(dirc-&gt;mask);
<a name="l74"></a> dirc-&gt;mask=</span><span class=cF5>StrNew</span><span class=cF0>(</span><span class=cF6>&quot;*&quot;</span><span class=cF0>);
<a name="l75"></a> }
<a name="l76"></a> </span><span class=cF5>Silent</span><span class=cF0>(old_silent);
<a name="l77"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l78"></a> }
<a name="l79"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l80"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l81"></a> </span><span class=cF5>Free</span><span class=cF0>(tmp_mask);
<a name="l82"></a> </span><span class=cF1>if</span><span class=cF0> (!valid) </span><span class=cF7>{</span><span class=cF0>
<a name="l83"></a> </span><span class=cF5>DirContextDel</span><span class=cF0>(dirc);
<a name="l84"></a> dirc=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l85"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l86"></a> </span><span class=cF1>return</span><span class=cF0> dirc;
<a name="l87"></a>}
</span></pre></body>
</html>