ZealOS/docs/Kernel/StrScan.CC.html

431 lines
41 KiB
HTML
Raw Normal View History

2021-07-03 05:07:57 +01:00
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.05">
<style type="text/css">
body {background-color:#000000;}
.cF0{color:#ffffff;background-color:#000000;}
.cF1{color:#3465a4;background-color:#000000;}
.cF2{color:#4e9a06;background-color:#000000;}
.cF3{color:#06989a;background-color:#000000;}
.cF4{color:#a24444;background-color:#000000;}
.cF5{color:#75507b;background-color:#000000;}
.cF6{color:#ce982f;background-color:#000000;}
.cF7{color:#bcc0b9;background-color:#000000;}
.cF8{color:#555753;background-color:#000000;}
.cF9{color:#729fcf;background-color:#000000;}
.cFA{color:#82bc49;background-color:#000000;}
.cFB{color:#34e2e2;background-color:#000000;}
.cFC{color:#ac3535;background-color:#000000;}
.cFD{color:#ad7fa8;background-color:#000000;}
.cFE{color:#fce94f;background-color:#000000;}
.cFF{color:#000000;background-color:#000000;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
2021-07-03 05:07:57 +01:00
<a name="l1"></a><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>Str2I64</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *st, </span><span class=cF9>I64</span><span class=cF0> radix=</span><span class=cFE>10</span><span class=cF0>, </span><span class=cF1>U8</span><span class=cF0> **_end_ptr=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l2"></a>{</span><span class=cF2>//String to I64. Similar to strtoul().</span><span class=cF0>
<a name="l3"></a></span><span class=cF2>//Allows radix change with &quot;0x20&quot; &quot;0b1010&quot; &quot;0d123&quot; &quot;0o18&quot;.</span><span class=cF0>
<a name="l4"></a> </span><span class=cF2>//Be careful of Str2I64(&quot;0b101&quot;, 16)--&gt;0xB101.</span><span class=cF0>
<a name="l5"></a> </span><span class=cF1>Bool</span><span class=cF0> neg = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l6"></a> </span><span class=cF9>I64</span><span class=cF0> ch, res = </span><span class=cFE>0</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l7"></a>
<a name="l8"></a> </span><span class=cF1>if</span><span class=cF0> (!st || !</span><span class=cF7>(</span><span class=cFE>2</span><span class=cF0> &lt;= radix &lt;= </span><span class=cFE>36</span><span class=cF7>)</span><span class=cF0>)
<a name="l9"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l10"></a> </span><span class=cF1>if</span><span class=cF0> (_end_ptr)
<a name="l11"></a> *_end_ptr = st;
<a name="l12"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>;
<a name="l13"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l14"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cFB>char_bmp_white_space</span><span class=cF0>, *st</span><span class=cF7>)</span><span class=cF0>)
<a name="l15"></a> st++;
<a name="l16"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l17"></a> </span><span class=cF1>switch</span><span class=cF0> (*st)
<a name="l18"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l19"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'-'</span><span class=cF0>:
<a name="l20"></a> st++;
<a name="l21"></a> neg = !neg;
<a name="l22"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l23"></a>
<a name="l24"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'+'</span><span class=cF0>:
<a name="l25"></a> st++;
<a name="l26"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l27"></a>
<a name="l28"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'0'</span><span class=cF0>:
<a name="l29"></a> st++;
<a name="l30"></a> ch = </span><span class=cF5>ToUpper</span><span class=cF0>(*st);
<a name="l31"></a> </span><span class=cF1>if</span><span class=cF0> (ch &gt;= </span><span class=cF6>'B'</span><span class=cF0> &amp;&amp; </span><span class=cF7>(</span><span class=cF0>radix &lt;= </span><span class=cFE>10</span><span class=cF0> || ch &gt; </span><span class=cF6>'A'</span><span class=cF0> + radix - </span><span class=cFE>11</span><span class=cF7>)</span><span class=cF0>)
<a name="l32"></a> </span><span class=cF1>switch</span><span class=cF0> (ch)
<a name="l33"></a> {
<a name="l34"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'B'</span><span class=cF0>: radix = </span><span class=cFE>2</span><span class=cF0>; st++; </span><span class=cF1>break</span><span class=cF0>;
<a name="l35"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'D'</span><span class=cF0>: radix = </span><span class=cFE>10</span><span class=cF0>; st++; </span><span class=cF1>break</span><span class=cF0>;
<a name="l36"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'X'</span><span class=cF0>: radix = </span><span class=cFE>16</span><span class=cF0>; st++; </span><span class=cF1>break</span><span class=cF0>;
<a name="l37"></a> }
<a name="l38"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l39"></a> </span><span class=cF1>goto</span><span class=cF0> ai_cont;
<a name="l40"></a> </span><span class=cF7>}</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l41"></a>ai_cont:
<a name="l42"></a> </span><span class=cF1>while</span><span class=cF0> (ch = </span><span class=cF5>ToUpper</span><span class=cF7>(</span><span class=cF0>*st++</span><span class=cF7>)</span><span class=cF0>)
<a name="l43"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l44"></a> </span><span class=cF1>if</span><span class=cF0> (radix &gt; </span><span class=cFE>10</span><span class=cF0>)
<a name="l45"></a> {
<a name="l46"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF6>'0'</span><span class=cF0> &lt;= ch &lt;= </span><span class=cF6>'9'</span><span class=cF0>)
<a name="l47"></a> res = res * radix + ch - </span><span class=cF6>'0'</span><span class=cF0>;
<a name="l48"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF6>'A'</span><span class=cF0> &lt;= ch &lt;= </span><span class=cF6>'A'</span><span class=cF0> + radix - </span><span class=cFE>11</span><span class=cF0>)
<a name="l49"></a> res = res * radix + ch - </span><span class=cF6>'A'</span><span class=cF0> + </span><span class=cFE>10</span><span class=cF0>;
<a name="l50"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l51"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l52"></a> }
<a name="l53"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF6>'0'</span><span class=cF0> &lt;= ch &lt;= </span><span class=cF6>'0'</span><span class=cF0> + radix - </span><span class=cFE>1</span><span class=cF0>)
<a name="l54"></a> res = res * radix + ch - </span><span class=cF6>'0'</span><span class=cF0>;
<a name="l55"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l56"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l57"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l58"></a> </span><span class=cF1>if</span><span class=cF0> (_end_ptr)
<a name="l59"></a> *_end_ptr = st - </span><span class=cFE>1</span><span class=cF0>;
<a name="l60"></a> </span><span class=cF1>if</span><span class=cF0> (neg)
<a name="l61"></a> </span><span class=cF1>return</span><span class=cF0> -res;
<a name="l62"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l63"></a> </span><span class=cF1>return</span><span class=cF0> res;
2021-07-03 05:07:57 +01:00
<a name="l64"></a>}
<a name="l65"></a>
<a name="l66"></a></span><span class=cF1>F64</span><span class=cF0> </span><span class=cF5>Str2F64</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *src, </span><span class=cF1>U8</span><span class=cF0> **_end_ptr=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l67"></a>{</span><span class=cF2>/*String to F64.</span><span class=cF0>
<a name="l68"></a></span><span class=cF2>Does not allow more than 18-digits</span><span class=cF0>
<a name="l69"></a></span><span class=cF2>before or after the decimal point</span><span class=cF0>
<a name="l70"></a></span><span class=cF2>because the numbers before and after</span><span class=cF0>
<a name="l71"></a></span><span class=cF2>the decimal point are stored</span><span class=cF0>
<a name="l72"></a></span><span class=cF2>in 64-bits. Use exponentiated forms</span><span class=cF0>
<a name="l73"></a></span><span class=cF2>to avoid this.</span><span class=cF0>
<a name="l74"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l75"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, k, ch;
<a name="l76"></a> </span><span class=cF1>F64</span><span class=cF0> d;
<a name="l77"></a> </span><span class=cF1>Bool</span><span class=cF0> neg = </span><span class=cF3>FALSE</span><span class=cF0>, neg_e = </span><span class=cF3>FALSE</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l78"></a>
<a name="l79"></a> ch = *src++;
<a name="l80"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cFB>char_bmp_white_space</span><span class=cF0>, ch</span><span class=cF7>)</span><span class=cF0>)
<a name="l81"></a> ch = *src++;
<a name="l82"></a> </span><span class=cF1>if</span><span class=cF0> (ch == </span><span class=cF6>'-'</span><span class=cF0>)
<a name="l83"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l84"></a> neg = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l85"></a> ch = *src++;
<a name="l86"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l87"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrNCompare</span><span class=cF7>(</span><span class=cF0>src - </span><span class=cFE>1</span><span class=cF0>, </span><span class=cF6>&quot;inf&quot;</span><span class=cF0>, </span><span class=cFE>3</span><span class=cF7>)</span><span class=cF0>)
<a name="l88"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l89"></a> d=</span><span class=cF3>inf</span><span class=cF0>;
<a name="l90"></a> src += </span><span class=cFE>3</span><span class=cF0>;
<a name="l91"></a> </span><span class=cF1>goto</span><span class=cF0> a2f_end;
<a name="l92"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l93"></a> </span><span class=cF1>if</span><span class=cF0> (*src == </span><span class=cF6>'inf'</span><span class=cF0>)
<a name="l94"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l95"></a> d = </span><span class=cF3>inf</span><span class=cF0>;
<a name="l96"></a> src++;
<a name="l97"></a> </span><span class=cF1>goto</span><span class=cF0> a2f_end;
<a name="l98"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l99"></a> i = </span><span class=cFE>0</span><span class=cF0>;
<a name="l100"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l101"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l102"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cFB>char_bmp_dec_numeric</span><span class=cF0>, ch</span><span class=cF7>)</span><span class=cF0>)
<a name="l103"></a> i = i * </span><span class=cFE>10</span><span class=cF0> + ch - </span><span class=cF6>'0'</span><span class=cF0>;
<a name="l104"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l105"></a> {
<a name="l106"></a> </span><span class=cF1>if</span><span class=cF0> (ch == </span><span class=cF6>'.'</span><span class=cF0> || ch == </span><span class=cF6>'e'</span><span class=cF0> || ch == </span><span class=cF6>'E'</span><span class=cF0>)
<a name="l107"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l108"></a> d = i;
<a name="l109"></a> </span><span class=cF1>goto</span><span class=cF0> a2f_end;
<a name="l110"></a> }
<a name="l111"></a> ch = *src++;
<a name="l112"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l113"></a> </span><span class=cF1>if</span><span class=cF0> (ch == </span><span class=cF6>'.'</span><span class=cF0>)
<a name="l114"></a> ch = *src++;
<a name="l115"></a> k = </span><span class=cFE>0</span><span class=cF0>;
<a name="l116"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l117"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l118"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cFB>char_bmp_dec_numeric</span><span class=cF0>, ch</span><span class=cF7>)</span><span class=cF0>)
<a name="l119"></a> {
<a name="l120"></a> i = i * </span><span class=cFE>10</span><span class=cF0> + ch - </span><span class=cF6>'0'</span><span class=cF0>;
<a name="l121"></a> k++;
<a name="l122"></a> }
<a name="l123"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l124"></a> {
<a name="l125"></a> </span><span class=cF1>if</span><span class=cF0> (ch == </span><span class=cF6>'e'</span><span class=cF0> || ch == </span><span class=cF6>'E'</span><span class=cF0>)
<a name="l126"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l127"></a> d = i * </span><span class=cF5>Pow10I64</span><span class=cF0>(-k);
<a name="l128"></a> </span><span class=cF1>goto</span><span class=cF0> a2f_end;
<a name="l129"></a> }
<a name="l130"></a> ch = *src++;
<a name="l131"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l132"></a> ch = *src++;
<a name="l133"></a> </span><span class=cF1>if</span><span class=cF0> (ch == </span><span class=cF6>'-'</span><span class=cF0>)
<a name="l134"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l135"></a> neg_e = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l136"></a> ch = *src++;
<a name="l137"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l138"></a> j = </span><span class=cFE>0</span><span class=cF0>;
<a name="l139"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l140"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l141"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cFB>char_bmp_dec_numeric</span><span class=cF0>, ch</span><span class=cF7>)</span><span class=cF0>)
<a name="l142"></a> j = j * </span><span class=cFE>10</span><span class=cF0> + ch - </span><span class=cF6>'0'</span><span class=cF0>;
<a name="l143"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l144"></a> {
<a name="l145"></a> </span><span class=cF1>if</span><span class=cF0> (neg_e)
<a name="l146"></a> d = i * </span><span class=cF5>Pow10I64</span><span class=cF0>(-j - k);
<a name="l147"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l148"></a> d = i * </span><span class=cF5>Pow10I64</span><span class=cF0>(j - k);
<a name="l149"></a> </span><span class=cF1>goto</span><span class=cF0> a2f_end;
<a name="l150"></a> }
<a name="l151"></a> ch = *src++;
<a name="l152"></a> </span><span class=cF7>}</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l153"></a>a2f_end:
<a name="l154"></a> </span><span class=cF1>if</span><span class=cF0> (_end_ptr)
<a name="l155"></a> *_end_ptr = src - </span><span class=cFE>1</span><span class=cF0>;
<a name="l156"></a> </span><span class=cF1>if</span><span class=cF0> (neg)
<a name="l157"></a> </span><span class=cF1>return</span><span class=cF0> -d;
<a name="l158"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l159"></a> </span><span class=cF1>return</span><span class=cF0> d;
2021-07-03 05:07:57 +01:00
<a name="l160"></a>}
<a name="l161"></a>
<a name="l162"></a></span><span class=cF9>CDate</span><span class=cF0> </span><span class=cF5>Str2Date</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *_src)
<a name="l163"></a>{</span><span class=cF2>/*&quot;*+nnnn&quot;, &quot;*-nnnn&quot;, &quot;mm/dd&quot;, &quot;mm/dd/yy&quot;</span><span class=cF0>
<a name="l164"></a></span><span class=cF2>It also supports some funs</span><span class=cF0>
<a name="l165"></a></span><span class=cF2>SM() start of mon</span><span class=cF0>
<a name="l166"></a></span><span class=cF2>EM() end of mon</span><span class=cF0>
<a name="l167"></a></span><span class=cF2>SY() start of year</span><span class=cF0>
<a name="l168"></a></span><span class=cF2>EY() end of year</span><span class=cF0>
<a name="l169"></a></span><span class=cF2>Full expressions are not implimented</span><span class=cF0>
<a name="l170"></a></span><span class=cF2>but you can do stuff like SM(*-7)+3</span><span class=cF0>
<a name="l171"></a></span><span class=cF2>and it will return the 3rd day after</span><span class=cF0>
<a name="l172"></a></span><span class=cF2>the start of mon for seven days before</span><span class=cF0>
<a name="l173"></a></span><span class=cF2>today.</span><span class=cF0>
<a name="l174"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l175"></a> </span><span class=cF9>CDate</span><span class=cF0> res = </span><span class=cFE>0</span><span class=cF0>;
<a name="l176"></a> </span><span class=cF9>CDateStruct</span><span class=cF0> ds, ds_now;
<a name="l177"></a> </span><span class=cF1>U8</span><span class=cF0> *src = </span><span class=cF5>MStrUtil</span><span class=cF0>(_src, </span><span class=cF3>SUF_REM_SPACES</span><span class=cF0> | </span><span class=cF3>SUF_TO_UPPER</span><span class=cF0>), *v = </span><span class=cF5>StrNew</span><span class=cF0>(src), *ptr = src;
<a name="l178"></a> </span><span class=cF1>Bool</span><span class=cF0> start_mon = </span><span class=cF3>FALSE</span><span class=cF0>, end_mon = </span><span class=cF3>FALSE</span><span class=cF0>, start_year = </span><span class=cF3>FALSE</span><span class=cF0>, end_year = </span><span class=cF3>FALSE</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l179"></a>
<a name="l180"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&amp;ds, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDateStruct</span><span class=cF7>)</span><span class=cF0>);
<a name="l181"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrNCompare</span><span class=cF7>(</span><span class=cF0>ptr, </span><span class=cF6>&quot;SM(&quot;</span><span class=cF0>, </span><span class=cFE>3</span><span class=cF7>)</span><span class=cF0>)
<a name="l182"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l183"></a> ptr += </span><span class=cFE>3</span><span class=cF0>;
<a name="l184"></a> start_mon = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l185"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l186"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrNCompare</span><span class=cF7>(</span><span class=cF0>ptr, </span><span class=cF6>&quot;EM(&quot;</span><span class=cF0>, </span><span class=cFE>3</span><span class=cF7>)</span><span class=cF0>)
<a name="l187"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l188"></a> ptr += </span><span class=cFE>3</span><span class=cF0>;
<a name="l189"></a> end_mon = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l190"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l191"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrNCompare</span><span class=cF7>(</span><span class=cF0>ptr, </span><span class=cF6>&quot;SY(&quot;</span><span class=cF0>, </span><span class=cFE>3</span><span class=cF7>)</span><span class=cF0>)
<a name="l192"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l193"></a> ptr += </span><span class=cFE>3</span><span class=cF0>;
<a name="l194"></a> start_year = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l195"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l196"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrNCompare</span><span class=cF7>(</span><span class=cF0>ptr, </span><span class=cF6>&quot;EY(&quot;</span><span class=cF0>, </span><span class=cFE>3</span><span class=cF7>)</span><span class=cF0>)
<a name="l197"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l198"></a> ptr += </span><span class=cFE>3</span><span class=cF0>;
<a name="l199"></a> end_year = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l200"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l201"></a> </span><span class=cF1>if</span><span class=cF0> (*ptr == </span><span class=cF6>'*'</span><span class=cF0>)
<a name="l202"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l203"></a> ptr++;
<a name="l204"></a> </span><span class=cF1>if</span><span class=cF0> (*ptr == </span><span class=cF6>'+'</span><span class=cF0> || *ptr == </span><span class=cF6>'-'</span><span class=cF0>)
<a name="l205"></a> res.date = </span><span class=cF5>Str2I64</span><span class=cF0>(ptr,, &amp;ptr);
<a name="l206"></a> res += </span><span class=cF5>Now</span><span class=cF0> + </span><span class=cFB>local_time_offset</span><span class=cF0>;
<a name="l207"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l208"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l209"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l210"></a> </span><span class=cF5>StrFirstRemove</span><span class=cF0>(ptr, </span><span class=cF6>&quot;/&quot;</span><span class=cF0>, v); </span><span class=cF2>//Put mon into v</span><span class=cF0>
<a name="l211"></a> ds.mon = </span><span class=cF5>Str2I64</span><span class=cF0>(v);
<a name="l212"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrOcc</span><span class=cF7>(</span><span class=cF0>ptr, </span><span class=cF6>'/'</span><span class=cF7>)</span><span class=cF0>)
<a name="l213"></a> {
<a name="l214"></a> </span><span class=cF5>StrFirstRemove</span><span class=cF0>(ptr, </span><span class=cF6>&quot;/&quot;</span><span class=cF0>, v); </span><span class=cF2>//Put day into v leaving year in ptr</span><span class=cF0>
<a name="l215"></a> ds.day_of_mon = </span><span class=cF5>Str2I64</span><span class=cF0>(v);
<a name="l216"></a> ds.year = </span><span class=cF5>Str2I64</span><span class=cF0>(ptr,, &amp;ptr);
<a name="l217"></a> </span><span class=cF1>if</span><span class=cF0> (ds.year &lt; </span><span class=cFE>100</span><span class=cF0>) </span><span class=cF2>//if not 4 digit year</span><span class=cF0>
<a name="l218"></a> ds.year += </span><span class=cFE>2000</span><span class=cF0>;
<a name="l219"></a> }
<a name="l220"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l221"></a> {
<a name="l222"></a> ds.day_of_mon = </span><span class=cF5>Str2I64</span><span class=cF0>(ptr,, &amp;ptr);
<a name="l223"></a> </span><span class=cF5>Date2Struct</span><span class=cF0>(&amp;ds_now, </span><span class=cF5>Now</span><span class=cF0> + </span><span class=cFB>local_time_offset</span><span class=cF0>);
<a name="l224"></a> ds.year = ds_now.year;
<a name="l225"></a> }
<a name="l226"></a> res = </span><span class=cF5>Struct2Date</span><span class=cF0>(&amp;ds);
<a name="l227"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l228"></a> </span><span class=cF1>if</span><span class=cF0> (*ptr == </span><span class=cF6>')'</span><span class=cF0>)
<a name="l229"></a> ptr++;
2021-07-03 05:07:57 +01:00
<a name="l230"></a>
<a name="l231"></a> </span><span class=cF1>if</span><span class=cF0> (start_mon)
<a name="l232"></a> res.date = </span><span class=cF5>FirstDayOfMon</span><span class=cF0>(res.date);
<a name="l233"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (end_mon)
<a name="l234"></a> res.date = </span><span class=cF5>LastDayOfMon</span><span class=cF0>(res.date);
<a name="l235"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (start_year)
<a name="l236"></a> res.date = </span><span class=cF5>FirstDayOfYear</span><span class=cF0>(res.date);
<a name="l237"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (end_year)
<a name="l238"></a> res.date = </span><span class=cF5>LastDayOfYear</span><span class=cF0>(res.date);
2021-07-03 05:07:57 +01:00
<a name="l239"></a>
<a name="l240"></a> </span><span class=cF1>if</span><span class=cF0> (*ptr == </span><span class=cF6>'+'</span><span class=cF0> || *ptr == </span><span class=cF6>'-'</span><span class=cF0>)
<a name="l241"></a> res.date += </span><span class=cF5>Str2I64</span><span class=cF0>(ptr);
<a name="l242"></a> </span><span class=cF5>Free</span><span class=cF0>(src);
<a name="l243"></a> </span><span class=cF5>Free</span><span class=cF0>(v);
2021-07-03 05:07:57 +01:00
<a name="l244"></a>
<a name="l245"></a> </span><span class=cF1>return</span><span class=cF0> res - </span><span class=cFB>local_time_offset</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l246"></a>}
<a name="l247"></a>
<a name="l248"></a></span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF5>StrScan</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *src, </span><span class=cF1>U8</span><span class=cF0> *format, ...)
<a name="l249"></a>{</span><span class=cF2>/*Opposite of sprintf(). Pass ptrs to data to be scanned-in.</span><span class=cF0>
<a name="l250"></a></span><span class=cF2>For &quot;%s&quot;, pass ptr to ptr (be careful because addr</span><span class=cF0>
<a name="l251"></a></span><span class=cF2>of array is the same as array--create ptr to array</span><span class=cF0>
<a name="l252"></a></span><span class=cF2>and take addr.</span><span class=cF0>
<a name="l253"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l254"></a> </span><span class=cF1>U8</span><span class=cF0> *buf, *ptr, **pptr;
<a name="l255"></a> </span><span class=cF1>Bool</span><span class=cF0> left_justify = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l256"></a> </span><span class=cF9>I64</span><span class=cF0> ch, cur_arg = </span><span class=cFE>0</span><span class=cF0>, i, len, *i_ptr, dec_len;
<a name="l257"></a> </span><span class=cF1>F64</span><span class=cF0> *d_ptr;
2021-07-03 05:07:57 +01:00
<a name="l258"></a>
<a name="l259"></a> </span><span class=cF1>if</span><span class=cF0> (!format)
<a name="l260"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l261"></a> </span><span class=cF1>while</span><span class=cF0> (ch = *format++)
<a name="l262"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l263"></a> </span><span class=cF1>if</span><span class=cF0> (ch == </span><span class=cF6>'%'</span><span class=cF0>)
<a name="l264"></a> {
<a name="l265"></a> </span><span class=cF1>if</span><span class=cF0> (*format == </span><span class=cF6>'%'</span><span class=cF0>)
<a name="l266"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l267"></a> src++;
<a name="l268"></a> format++;
<a name="l269"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l270"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l271"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l272"></a> </span><span class=cF1>if</span><span class=cF0> (*format == </span><span class=cF6>'-'</span><span class=cF0>)
<a name="l273"></a> {
<a name="l274"></a> left_justify = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l275"></a> format++;
<a name="l276"></a> }
<a name="l277"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l278"></a> left_justify = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l279"></a> len = </span><span class=cFE>0</span><span class=cF0>;
<a name="l280"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF6>'0'</span><span class=cF0> &lt;= *format &lt;= </span><span class=cF6>'9'</span><span class=cF0>)
<a name="l281"></a> len = len * </span><span class=cFE>10</span><span class=cF0> + (*format++ - </span><span class=cF6>'0'</span><span class=cF0>);
<a name="l282"></a> </span><span class=cF1>if</span><span class=cF0> (*format == </span><span class=cF6>'*'</span><span class=cF0>)
<a name="l283"></a> {
<a name="l284"></a> format++;
<a name="l285"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg &gt;= argc)
<a name="l286"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l287"></a> len = argv[cur_arg++];
<a name="l288"></a> }
<a name="l289"></a> ch = *format++;
<a name="l290"></a> </span><span class=cF1>if</span><span class=cF0> (ch &amp;&amp; !len)
<a name="l291"></a> {
<a name="l292"></a> ptr = src;
<a name="l293"></a> </span><span class=cF1>while</span><span class=cF0> (*ptr &amp;&amp; *ptr != *format)
<a name="l294"></a> ptr++;
<a name="l295"></a> len = ptr - src;
<a name="l296"></a> }
<a name="l297"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l298"></a> {
<a name="l299"></a> </span><span class=cF1>if</span><span class=cF0> (ch == </span><span class=cF6>'.'</span><span class=cF0>)
<a name="l300"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l301"></a> dec_len = </span><span class=cFE>0</span><span class=cF0>;
<a name="l302"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF6>'0'</span><span class=cF0> &lt;= *format &lt;= </span><span class=cF6>'9'</span><span class=cF0>)
<a name="l303"></a> dec_len = dec_len * </span><span class=cFE>10</span><span class=cF0> + (*format++ - </span><span class=cF6>'0'</span><span class=cF0>);
<a name="l304"></a> </span><span class=cF1>if</span><span class=cF0> (*format == </span><span class=cF6>'*'</span><span class=cF0>)
<a name="l305"></a> {
<a name="l306"></a> format++;
<a name="l307"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg &gt;= argc)
<a name="l308"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l309"></a> dec_len = argv[cur_arg++];
<a name="l310"></a> }
<a name="l311"></a> ch = *format++;
<a name="l312"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l313"></a> }
<a name="l314"></a> buf = </span><span class=cF5>MAlloc</span><span class=cF0>(len + </span><span class=cFE>1</span><span class=cF0>);
<a name="l315"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; len; i++)
<a name="l316"></a> buf[i] = *src++;
<a name="l317"></a> buf[i] = </span><span class=cFE>0</span><span class=cF0>;
<a name="l318"></a> </span><span class=cF1>switch</span><span class=cF0> (ch)
<a name="l319"></a> {
<a name="l320"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'s'</span><span class=cF0>:
<a name="l321"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg &gt;= argc)
<a name="l322"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l323"></a> pptr = argv[cur_arg++];
<a name="l324"></a> </span><span class=cF5>StrCopy</span><span class=cF0>(*pptr, buf);
<a name="l325"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l326"></a>
<a name="l327"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'c'</span><span class=cF0>:
<a name="l328"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg &gt;= argc)
<a name="l329"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l330"></a> ptr = argv[cur_arg++];
<a name="l331"></a> *ptr = *buf;
<a name="l332"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l333"></a>
<a name="l334"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'C'</span><span class=cF0>:
<a name="l335"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg &gt;= argc)
<a name="l336"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l337"></a> ptr = argv[cur_arg++];
<a name="l338"></a> *ptr = </span><span class=cF5>ToUpper</span><span class=cF0>(*buf);
<a name="l339"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l340"></a>
<a name="l341"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'z'</span><span class=cF0>:
<a name="l342"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg + </span><span class=cFE>1</span><span class=cF0> &gt;= argc)
<a name="l343"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l344"></a> i_ptr = argv[cur_arg++];
<a name="l345"></a> *i_ptr = </span><span class=cF5>ListMatch</span><span class=cF0>(buf, argv[cur_arg++]);
<a name="l346"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l347"></a>
<a name="l348"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'Z'</span><span class=cF0>:
<a name="l349"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg + </span><span class=cFE>1</span><span class=cF0> &gt;= argc)
<a name="l350"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l351"></a> i_ptr = argv[cur_arg++];
<a name="l352"></a> *i_ptr = </span><span class=cF5>DefineMatch</span><span class=cF0>(buf, argv[cur_arg++]);
<a name="l353"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l354"></a>
<a name="l355"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'d'</span><span class=cF0>:
<a name="l356"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg &gt;= argc)
<a name="l357"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l358"></a> i_ptr = argv[cur_arg++];
<a name="l359"></a> *i_ptr = </span><span class=cF5>Str2I64</span><span class=cF0>(buf);
<a name="l360"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l361"></a>
<a name="l362"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'X'</span><span class=cF0>:
<a name="l363"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg &gt;= argc)
<a name="l364"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l365"></a> i_ptr = argv[cur_arg++];
<a name="l366"></a> *i_ptr = </span><span class=cF5>Str2I64</span><span class=cF0>(buf, </span><span class=cFE>16</span><span class=cF0>);
<a name="l367"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l368"></a>
<a name="l369"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'b'</span><span class=cF0>:
<a name="l370"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg &gt;= argc)
<a name="l371"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l372"></a> i_ptr = argv[cur_arg++];
<a name="l373"></a> *i_ptr = </span><span class=cF5>Str2I64</span><span class=cF0>(buf, </span><span class=cFE>2</span><span class=cF0>);
<a name="l374"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l375"></a>
<a name="l376"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'e'</span><span class=cF0>:
<a name="l377"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'f'</span><span class=cF0>:
<a name="l378"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'g'</span><span class=cF0>:
<a name="l379"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'n'</span><span class=cF0>:
<a name="l380"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg &gt;= argc)
<a name="l381"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l382"></a> d_ptr = argv[cur_arg++];
<a name="l383"></a> *d_ptr = </span><span class=cF5>Str2F64</span><span class=cF0>(buf);
<a name="l384"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l385"></a>
<a name="l386"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'D'</span><span class=cF0>:
<a name="l387"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg &gt;= argc)
<a name="l388"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
<a name="l389"></a> i_ptr = argv[cur_arg++];
<a name="l390"></a> *i_ptr = </span><span class=cF5>Str2Date</span><span class=cF0>(buf);
<a name="l391"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l392"></a> }
<a name="l393"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l394"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l395"></a> }
<a name="l396"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l397"></a> src++;
<a name="l398"></a> </span><span class=cF7>}</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l399"></a>
<a name="l400"></a> </span><span class=cF1>return</span><span class=cF0> src;
2021-07-03 05:07:57 +01:00
<a name="l401"></a>}
</span></pre></body>
</html>