371 lines
35 KiB
HTML
Executable File
371 lines
35 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=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=10,</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 "0x20" "0b1010" "0d123" "0o18".</span><span class=cF0>
|
|
<a name="l4"></a> </span><span class=cF2>//Be careful of Str2I64("0b101",16)-->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=0;
|
|
<a name="l7"></a> </span><span class=cF1>if</span><span class=cF0> (!st || !</span><span class=cF7>(</span><span class=cF0>2<=radix<=36</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l8"></a> </span><span class=cF1>if</span><span class=cF0> (_end_ptr) *_end_ptr=st;
|
|
<a name="l9"></a> </span><span class=cF1>return</span><span class=cF0> 0;
|
|
<a name="l10"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l11"></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="l12"></a> st++;
|
|
<a name="l13"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
|
|
<a name="l14"></a> </span><span class=cF1>switch</span><span class=cF0> (*st) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l15"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'-'</span><span class=cF0>:
|
|
<a name="l16"></a> st++;
|
|
<a name="l17"></a> neg=!neg;
|
|
<a name="l18"></a> </span><span class=cF1>break</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> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l22"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'0'</span><span class=cF0>:
|
|
<a name="l23"></a> st++;
|
|
<a name="l24"></a> ch=</span><span class=cF5>ToUpper</span><span class=cF0>(*st);
|
|
<a name="l25"></a> </span><span class=cF1>if</span><span class=cF0> (ch>=</span><span class=cF6>'B'</span><span class=cF0> && </span><span class=cF7>(</span><span class=cF0>radix<=10 || ch></span><span class=cF6>'A'</span><span class=cF0>+radix-11</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l26"></a> </span><span class=cF1>switch</span><span class=cF0> (ch) {
|
|
<a name="l27"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'B'</span><span class=cF0>: radix=2; st++; </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=cF6>'D'</span><span class=cF0>: radix=10; st++; </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l29"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'X'</span><span class=cF0>: radix=16; st++; </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l30"></a> }
|
|
<a name="l31"></a> </span><span class=cF1>default</span><span class=cF0>:
|
|
<a name="l32"></a> </span><span class=cF1>goto</span><span class=cF0> ai_cont;
|
|
<a name="l33"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l34"></a>ai_cont:
|
|
<a name="l35"></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>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l36"></a> </span><span class=cF1>if</span><span class=cF0> (radix>10) {
|
|
<a name="l37"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF6>'0'</span><span class=cF0><=ch<=</span><span class=cF6>'9'</span><span class=cF0>)
|
|
<a name="l38"></a> res=res*radix+ch-</span><span class=cF6>'0'</span><span class=cF0>;
|
|
<a name="l39"></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><=ch<=</span><span class=cF6>'A'</span><span class=cF0>+radix-11)
|
|
<a name="l40"></a> res=res*radix+ch-</span><span class=cF6>'A'</span><span class=cF0>+10;
|
|
<a name="l41"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l42"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l43"></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><=ch<=</span><span class=cF6>'0'</span><span class=cF0>+radix-1)
|
|
<a name="l44"></a> res=res*radix+ch-</span><span class=cF6>'0'</span><span class=cF0>;
|
|
<a name="l45"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l46"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l47"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l48"></a> </span><span class=cF1>if</span><span class=cF0> (_end_ptr) *_end_ptr=st-1;
|
|
<a name="l49"></a> </span><span class=cF1>if</span><span class=cF0> (neg)
|
|
<a name="l50"></a> </span><span class=cF1>return</span><span class=cF0> -res;
|
|
<a name="l51"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l52"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
|
<a name="l53"></a>}
|
|
<a name="l54"></a>
|
|
<a name="l55"></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="l56"></a>{</span><span class=cF2>/*String to F64.</span><span class=cF0>
|
|
<a name="l57"></a></span><span class=cF2>Does not allow more than 18-digits</span><span class=cF0>
|
|
<a name="l58"></a></span><span class=cF2>before or after the decimal point</span><span class=cF0>
|
|
<a name="l59"></a></span><span class=cF2>because the numbers before and after</span><span class=cF0>
|
|
<a name="l60"></a></span><span class=cF2>the decimal point are stored</span><span class=cF0>
|
|
<a name="l61"></a></span><span class=cF2>in 64-bits. Use exponentiated forms</span><span class=cF0>
|
|
<a name="l62"></a></span><span class=cF2>to avoid this.</span><span class=cF0>
|
|
<a name="l63"></a></span><span class=cF2>*/</span><span class=cF0>
|
|
<a name="l64"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,k,ch;
|
|
<a name="l65"></a> </span><span class=cF1>F64</span><span class=cF0> d;
|
|
<a name="l66"></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>;
|
|
<a name="l67"></a>
|
|
<a name="l68"></a> ch=*src++;
|
|
<a name="l69"></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="l70"></a> ch=*src++;
|
|
<a name="l71"></a> </span><span class=cF1>if</span><span class=cF0> (ch==</span><span class=cF6>'-'</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l72"></a> neg=</span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l73"></a> ch=*src++;
|
|
<a name="l74"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l75"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrNCmp</span><span class=cF7>(</span><span class=cF0>src-1,</span><span class=cF6>"inf"</span><span class=cF0>,3</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l76"></a> d=</span><span class=cF3>inf</span><span class=cF0>;
|
|
<a name="l77"></a> src+=3;
|
|
<a name="l78"></a> </span><span class=cF1>goto</span><span class=cF0> a2f_end;
|
|
<a name="l79"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l80"></a> </span><span class=cF1>if</span><span class=cF0> (*src==</span><span class=cF6>'inf'</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l81"></a> d=</span><span class=cF3>inf</span><span class=cF0>;
|
|
<a name="l82"></a> src++;
|
|
<a name="l83"></a> </span><span class=cF1>goto</span><span class=cF0> a2f_end;
|
|
<a name="l84"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l85"></a> i=0;
|
|
<a name="l86"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) </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>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="l88"></a> i=i*10+ch-</span><span class=cF6>'0'</span><span class=cF0>;
|
|
<a name="l89"></a> </span><span class=cF1>else</span><span class=cF0> {
|
|
<a name="l90"></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="l91"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l92"></a> d=i;
|
|
<a name="l93"></a> </span><span class=cF1>goto</span><span class=cF0> a2f_end;
|
|
<a name="l94"></a> }
|
|
<a name="l95"></a> ch=*src++;
|
|
<a name="l96"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l97"></a> </span><span class=cF1>if</span><span class=cF0> (ch==</span><span class=cF6>'.'</span><span class=cF0>)
|
|
<a name="l98"></a> ch=*src++;
|
|
<a name="l99"></a> k=0;
|
|
<a name="l100"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l101"></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="l102"></a> i=i*10+ch-</span><span class=cF6>'0'</span><span class=cF0>;
|
|
<a name="l103"></a> k++;
|
|
<a name="l104"></a> } </span><span class=cF1>else</span><span class=cF0> {
|
|
<a name="l105"></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="l106"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l107"></a> d=i*</span><span class=cF5>Pow10I64</span><span class=cF0>(-k);
|
|
<a name="l108"></a> </span><span class=cF1>goto</span><span class=cF0> a2f_end;
|
|
<a name="l109"></a> }
|
|
<a name="l110"></a> ch=*src++;
|
|
<a name="l111"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l112"></a> ch=*src++;
|
|
<a name="l113"></a> </span><span class=cF1>if</span><span class=cF0> (ch==</span><span class=cF6>'-'</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l114"></a> neg_e=</span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l115"></a> ch=*src++;
|
|
<a name="l116"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l117"></a> j=0;
|
|
<a name="l118"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l119"></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="l120"></a> j=j*10+ch-</span><span class=cF6>'0'</span><span class=cF0>;
|
|
<a name="l121"></a> </span><span class=cF1>else</span><span class=cF0> {
|
|
<a name="l122"></a> </span><span class=cF1>if</span><span class=cF0> (neg_e)
|
|
<a name="l123"></a> d=i*</span><span class=cF5>Pow10I64</span><span class=cF0>(-j-k);
|
|
<a name="l124"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l125"></a> d=i*</span><span class=cF5>Pow10I64</span><span class=cF0>(j-k);
|
|
<a name="l126"></a> </span><span class=cF1>goto</span><span class=cF0> a2f_end;
|
|
<a name="l127"></a> }
|
|
<a name="l128"></a> ch=*src++;
|
|
<a name="l129"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l130"></a>a2f_end:
|
|
<a name="l131"></a> </span><span class=cF1>if</span><span class=cF0> (_end_ptr) *_end_ptr=src-1;
|
|
<a name="l132"></a> </span><span class=cF1>if</span><span class=cF0> (neg)
|
|
<a name="l133"></a> </span><span class=cF1>return</span><span class=cF0> -d;
|
|
<a name="l134"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l135"></a> </span><span class=cF1>return</span><span class=cF0> d;
|
|
<a name="l136"></a>}
|
|
<a name="l137"></a>
|
|
<a name="l138"></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="l139"></a>{</span><span class=cF2>/*"*+nnnn", "*-nnnn", "mm/dd", "mm/dd/yy"</span><span class=cF0>
|
|
<a name="l140"></a></span><span class=cF2>It also supports some funs</span><span class=cF0>
|
|
<a name="l141"></a></span><span class=cF2>SM() start of mon</span><span class=cF0>
|
|
<a name="l142"></a></span><span class=cF2>EM() end of mon</span><span class=cF0>
|
|
<a name="l143"></a></span><span class=cF2>SY() start of year</span><span class=cF0>
|
|
<a name="l144"></a></span><span class=cF2>EY() end of year</span><span class=cF0>
|
|
<a name="l145"></a></span><span class=cF2>Full expressions are not implimented</span><span class=cF0>
|
|
<a name="l146"></a></span><span class=cF2>but you can do stuff like SM(*-7)+3</span><span class=cF0>
|
|
<a name="l147"></a></span><span class=cF2>and it will return the 3rd day after</span><span class=cF0>
|
|
<a name="l148"></a></span><span class=cF2>the start of mon for seven days before</span><span class=cF0>
|
|
<a name="l149"></a></span><span class=cF2>today.</span><span class=cF0>
|
|
<a name="l150"></a></span><span class=cF2>*/</span><span class=cF0>
|
|
<a name="l151"></a> </span><span class=cF9>CDate</span><span class=cF0> res=0;
|
|
<a name="l152"></a> </span><span class=cF9>CDateStruct</span><span class=cF0> ds,ds_now;
|
|
<a name="l153"></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>),
|
|
<a name="l154"></a> *v=</span><span class=cF5>StrNew</span><span class=cF0>(src),
|
|
<a name="l155"></a> *ptr=src;
|
|
<a name="l156"></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>,
|
|
<a name="l157"></a> start_year=</span><span class=cF3>FALSE</span><span class=cF0>,end_year=</span><span class=cF3>FALSE</span><span class=cF0>;
|
|
<a name="l158"></a>
|
|
<a name="l159"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&ds,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDateStruct</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l160"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrNCmp</span><span class=cF7>(</span><span class=cF0>ptr,</span><span class=cF6>"SM("</span><span class=cF0>,3</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l161"></a> ptr+=3;
|
|
<a name="l162"></a> start_mon=</span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l163"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrNCmp</span><span class=cF7>(</span><span class=cF0>ptr,</span><span class=cF6>"EM("</span><span class=cF0>,3</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l164"></a> ptr+=3;
|
|
<a name="l165"></a> end_mon=</span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l166"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrNCmp</span><span class=cF7>(</span><span class=cF0>ptr,</span><span class=cF6>"SY("</span><span class=cF0>,3</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l167"></a> ptr+=3;
|
|
<a name="l168"></a> start_year=</span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l169"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrNCmp</span><span class=cF7>(</span><span class=cF0>ptr,</span><span class=cF6>"EY("</span><span class=cF0>,3</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l170"></a> ptr+=3;
|
|
<a name="l171"></a> end_year=</span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l172"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l173"></a> </span><span class=cF1>if</span><span class=cF0> (*ptr==</span><span class=cF6>'*'</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l174"></a> ptr++;
|
|
<a name="l175"></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="l176"></a> res.date=</span><span class=cF5>Str2I64</span><span class=cF0>(ptr,,&ptr);
|
|
<a name="l177"></a> res+=</span><span class=cF5>Now</span><span class=cF0>+</span><span class=cFB>local_time_offset</span><span class=cF0>;
|
|
<a name="l178"></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="l179"></a> </span><span class=cF5>StrFirstRem</span><span class=cF0>(ptr,</span><span class=cF6>"/"</span><span class=cF0>,v); </span><span class=cF2>//Put mon into v</span><span class=cF0>
|
|
<a name="l180"></a> ds.mon=</span><span class=cF5>Str2I64</span><span class=cF0>(v);
|
|
<a name="l181"></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="l182"></a> </span><span class=cF5>StrFirstRem</span><span class=cF0>(ptr,</span><span class=cF6>"/"</span><span class=cF0>,v); </span><span class=cF2>//Put day into v leaving year in ptr</span><span class=cF0>
|
|
<a name="l183"></a> ds.day_of_mon=</span><span class=cF5>Str2I64</span><span class=cF0>(v);
|
|
<a name="l184"></a> ds.year=</span><span class=cF5>Str2I64</span><span class=cF0>(ptr,,&ptr);
|
|
<a name="l185"></a> </span><span class=cF1>if</span><span class=cF0> (ds.year<100) </span><span class=cF2>//if not 4 digit year</span><span class=cF0>
|
|
<a name="l186"></a> ds.year+=2000;
|
|
<a name="l187"></a> } </span><span class=cF1>else</span><span class=cF0> {
|
|
<a name="l188"></a> ds.day_of_mon=</span><span class=cF5>Str2I64</span><span class=cF0>(ptr,,&ptr);
|
|
<a name="l189"></a> </span><span class=cF5>Date2Struct</span><span class=cF0>(&ds_now,</span><span class=cF5>Now</span><span class=cF0>+</span><span class=cFB>local_time_offset</span><span class=cF0>);
|
|
<a name="l190"></a> ds.year=ds_now.year;
|
|
<a name="l191"></a> }
|
|
<a name="l192"></a> res=</span><span class=cF5>Struct2Date</span><span class=cF0>(&ds);
|
|
<a name="l193"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l194"></a> </span><span class=cF1>if</span><span class=cF0> (*ptr==</span><span class=cF6>')'</span><span class=cF0>) ptr++;
|
|
<a name="l195"></a>
|
|
<a name="l196"></a> </span><span class=cF1>if</span><span class=cF0> (start_mon)
|
|
<a name="l197"></a> res.date=</span><span class=cF5>FirstDayOfMon</span><span class=cF0>(res.date);
|
|
<a name="l198"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (end_mon)
|
|
<a name="l199"></a> res.date=</span><span class=cF5>LastDayOfMon</span><span class=cF0>(res.date);
|
|
<a name="l200"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (start_year)
|
|
<a name="l201"></a> res.date=</span><span class=cF5>FirstDayOfYear</span><span class=cF0>(res.date);
|
|
<a name="l202"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (end_year)
|
|
<a name="l203"></a> res.date=</span><span class=cF5>LastDayOfYear</span><span class=cF0>(res.date);
|
|
<a name="l204"></a>
|
|
<a name="l205"></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="l206"></a> res.date+=</span><span class=cF5>Str2I64</span><span class=cF0>(ptr);
|
|
<a name="l207"></a> </span><span class=cF5>Free</span><span class=cF0>(src);
|
|
<a name="l208"></a> </span><span class=cF5>Free</span><span class=cF0>(v);
|
|
<a name="l209"></a> </span><span class=cF1>return</span><span class=cF0> res-</span><span class=cFB>local_time_offset</span><span class=cF0>;
|
|
<a name="l210"></a>}
|
|
<a name="l211"></a>
|
|
<a name="l212"></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> *fmt,...)
|
|
<a name="l213"></a>{</span><span class=cF2>/*Opposite of sprintf(). Pass ptrs to data to be scanned-in.</span><span class=cF0>
|
|
<a name="l214"></a></span><span class=cF2>For "%s", pass ptr to ptr (be careful because addr</span><span class=cF0>
|
|
<a name="l215"></a></span><span class=cF2>of array is the same as array--create ptr to array</span><span class=cF0>
|
|
<a name="l216"></a></span><span class=cF2>and take addr.</span><span class=cF0>
|
|
<a name="l217"></a></span><span class=cF2>*/</span><span class=cF0>
|
|
<a name="l218"></a> </span><span class=cF1>U8</span><span class=cF0> *buf,*ptr,**pptr;
|
|
<a name="l219"></a> </span><span class=cF1>Bool</span><span class=cF0> left_justify=</span><span class=cF3>FALSE</span><span class=cF0>;
|
|
<a name="l220"></a> </span><span class=cF9>I64</span><span class=cF0> ch,cur_arg=0,i,len,*i_ptr,dec_len;
|
|
<a name="l221"></a> </span><span class=cF1>F64</span><span class=cF0> *d_ptr;
|
|
<a name="l222"></a> </span><span class=cF1>if</span><span class=cF0> (!fmt)
|
|
<a name="l223"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
|
|
<a name="l224"></a> </span><span class=cF1>while</span><span class=cF0> (ch = *fmt++) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l225"></a> </span><span class=cF1>if</span><span class=cF0> (ch==</span><span class=cF6>'%'</span><span class=cF0>) {
|
|
<a name="l226"></a> </span><span class=cF1>if</span><span class=cF0> (*fmt==</span><span class=cF6>'%'</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l227"></a> src++;
|
|
<a name="l228"></a> fmt++;
|
|
<a name="l229"></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="l230"></a> </span><span class=cF1>if</span><span class=cF0> (*fmt==</span><span class=cF6>'-'</span><span class=cF0>) {
|
|
<a name="l231"></a> left_justify=</span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l232"></a> fmt++;
|
|
<a name="l233"></a> } </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l234"></a> left_justify=</span><span class=cF3>FALSE</span><span class=cF0>;
|
|
<a name="l235"></a> len=0;
|
|
<a name="l236"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF6>'0'</span><span class=cF0><=*fmt<=</span><span class=cF6>'9'</span><span class=cF0>)
|
|
<a name="l237"></a> len=len*10+ (*fmt++ -</span><span class=cF6>'0'</span><span class=cF0>);
|
|
<a name="l238"></a> </span><span class=cF1>if</span><span class=cF0> (*fmt==</span><span class=cF6>'*'</span><span class=cF0>) {
|
|
<a name="l239"></a> fmt++;
|
|
<a name="l240"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg>=argc)
|
|
<a name="l241"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
|
|
<a name="l242"></a> len=argv[cur_arg++];
|
|
<a name="l243"></a> }
|
|
<a name="l244"></a> ch=*fmt++;
|
|
<a name="l245"></a> </span><span class=cF1>if</span><span class=cF0> (ch && !len) {
|
|
<a name="l246"></a> ptr=src;
|
|
<a name="l247"></a> </span><span class=cF1>while</span><span class=cF0> (*ptr && *ptr!=*fmt)
|
|
<a name="l248"></a> ptr++;
|
|
<a name="l249"></a> len=ptr-src;
|
|
<a name="l250"></a> } </span><span class=cF1>else</span><span class=cF0> {
|
|
<a name="l251"></a> </span><span class=cF1>if</span><span class=cF0> (ch==</span><span class=cF6>'.'</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l252"></a> dec_len=0;
|
|
<a name="l253"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF6>'0'</span><span class=cF0><=*fmt<=</span><span class=cF6>'9'</span><span class=cF0>)
|
|
<a name="l254"></a> dec_len=dec_len*10+ (*fmt++-</span><span class=cF6>'0'</span><span class=cF0>);
|
|
<a name="l255"></a> </span><span class=cF1>if</span><span class=cF0> (*fmt==</span><span class=cF6>'*'</span><span class=cF0>) {
|
|
<a name="l256"></a> fmt++;
|
|
<a name="l257"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg>=argc)
|
|
<a name="l258"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
|
|
<a name="l259"></a> dec_len=argv[cur_arg++];
|
|
<a name="l260"></a> }
|
|
<a name="l261"></a> ch=*fmt++;
|
|
<a name="l262"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l263"></a> }
|
|
<a name="l264"></a> buf=</span><span class=cF5>MAlloc</span><span class=cF0>(len+1);
|
|
<a name="l265"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<len;i++)
|
|
<a name="l266"></a> buf[i]=*src++;
|
|
<a name="l267"></a> buf[i]=0;
|
|
<a name="l268"></a> </span><span class=cF1>switch</span><span class=cF0> (ch) {
|
|
<a name="l269"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'s'</span><span class=cF0>:
|
|
<a name="l270"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg>=argc)
|
|
<a name="l271"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
|
|
<a name="l272"></a> pptr=argv[cur_arg++];
|
|
<a name="l273"></a> </span><span class=cF5>StrCpy</span><span class=cF0>(*pptr,buf);
|
|
<a name="l274"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l275"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'c'</span><span class=cF0>:
|
|
<a name="l276"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg>=argc)
|
|
<a name="l277"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
|
|
<a name="l278"></a> ptr=argv[cur_arg++];
|
|
<a name="l279"></a> *ptr=*buf;
|
|
<a name="l280"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l281"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'C'</span><span class=cF0>:
|
|
<a name="l282"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg>=argc)
|
|
<a name="l283"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
|
|
<a name="l284"></a> ptr=argv[cur_arg++];
|
|
<a name="l285"></a> *ptr=</span><span class=cF5>ToUpper</span><span class=cF0>(*buf);
|
|
<a name="l286"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l287"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'z'</span><span class=cF0>:
|
|
<a name="l288"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg+1>=argc)
|
|
<a name="l289"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
|
|
<a name="l290"></a> i_ptr=argv[cur_arg++];
|
|
<a name="l291"></a> *i_ptr=</span><span class=cF5>LstMatch</span><span class=cF0>(buf,argv[cur_arg++]);
|
|
<a name="l292"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l293"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'Z'</span><span class=cF0>:
|
|
<a name="l294"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg+1>=argc)
|
|
<a name="l295"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
|
|
<a name="l296"></a> i_ptr=argv[cur_arg++];
|
|
<a name="l297"></a> *i_ptr=</span><span class=cF5>DefineMatch</span><span class=cF0>(buf,argv[cur_arg++]);
|
|
<a name="l298"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l299"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'d'</span><span class=cF0>:
|
|
<a name="l300"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg>=argc)
|
|
<a name="l301"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
|
|
<a name="l302"></a> i_ptr=argv[cur_arg++];
|
|
<a name="l303"></a> *i_ptr=</span><span class=cF5>Str2I64</span><span class=cF0>(buf);
|
|
<a name="l304"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l305"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'X'</span><span class=cF0>:
|
|
<a name="l306"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg>=argc)
|
|
<a name="l307"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
|
|
<a name="l308"></a> i_ptr=argv[cur_arg++];
|
|
<a name="l309"></a> *i_ptr=</span><span class=cF5>Str2I64</span><span class=cF0>(buf,16);
|
|
<a name="l310"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l311"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'b'</span><span class=cF0>:
|
|
<a name="l312"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg>=argc)
|
|
<a name="l313"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
|
|
<a name="l314"></a> i_ptr=argv[cur_arg++];
|
|
<a name="l315"></a> *i_ptr=</span><span class=cF5>Str2I64</span><span class=cF0>(buf,2);
|
|
<a name="l316"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l317"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'e'</span><span class=cF0>:
|
|
<a name="l318"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'f'</span><span class=cF0>:
|
|
<a name="l319"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'g'</span><span class=cF0>:
|
|
<a name="l320"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'n'</span><span class=cF0>:
|
|
<a name="l321"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg>=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> d_ptr=argv[cur_arg++];
|
|
<a name="l324"></a> *d_ptr=</span><span class=cF5>Str2F64</span><span class=cF0>(buf);
|
|
<a name="l325"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l326"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'D'</span><span class=cF0>:
|
|
<a name="l327"></a> </span><span class=cF1>if</span><span class=cF0> (cur_arg>=argc)
|
|
<a name="l328"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Scan'</span><span class=cF0>);
|
|
<a name="l329"></a> i_ptr=argv[cur_arg++];
|
|
<a name="l330"></a> *i_ptr=</span><span class=cF5>Str2Date</span><span class=cF0>(buf);
|
|
<a name="l331"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l332"></a> }
|
|
<a name="l333"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
|
|
<a name="l334"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l335"></a> } </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l336"></a> src++;
|
|
<a name="l337"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l338"></a> </span><span class=cF1>return</span><span class=cF0> src;
|
|
<a name="l339"></a>}
|
|
</span></pre></body>
|
|
</html>
|