128 lines
7.9 KiB
Plaintext
128 lines
7.9 KiB
Plaintext
|
<!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=cF0>#</span><span class=cF1>define</span><span class=cF0> BORDER_CHARS 1
|
||
|
<a name="l2"></a>
|
||
|
<a name="l3"></a></span><span class=cF1>U8</span><span class=cF0> *buf;
|
||
|
<a name="l4"></a></span><span class=cF9>I64</span><span class=cF0> size,mp_not_done_flags;
|
||
|
<a name="l5"></a></span><span class=cF9>CDoc</span><span class=cF0> *doc;
|
||
|
<a name="l6"></a>
|
||
|
<a name="l7"></a></span><span class=cF1>U0</span><span class=cF0> PDNormalize()
|
||
|
<a name="l8"></a>{
|
||
|
<a name="l9"></a> </span><span class=cF1>U8</span><span class=cF0> *r=</span><span class=cF5>MAlloc</span><span class=cF0>(size+2*BORDER_CHARS),
|
||
|
<a name="l10"></a> *src=buf,*dst=r;
|
||
|
<a name="l11"></a> </span><span class=cF9>I64</span><span class=cF0> ch;
|
||
|
<a name="l12"></a> *dst++=</span><span class=cF6>'['</span><span class=cF0>; </span><span class=cF2>//Border</span><span class=cF0>
|
||
|
<a name="l13"></a> </span><span class=cF1>while</span><span class=cF0> (size--) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l14"></a> ch=*src++;
|
||
|
<a name="l15"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF6>'a'</span><span class=cF0><=ch<=</span><span class=cF6>'z'</span><span class=cF0>) </span><span class=cF2>//lower is most common so do first</span><span class=cF0>
|
||
|
<a name="l16"></a> *dst++=ch;
|
||
|
<a name="l17"></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>'Z'</span><span class=cF0>)
|
||
|
<a name="l18"></a> *dst++=ch+</span><span class=cF6>'a'</span><span class=cF0>-</span><span class=cF6>'A'</span><span class=cF0>; </span><span class=cF2>//Convert to lower</span><span class=cF0>
|
||
|
<a name="l19"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l20"></a> *dst++=</span><span class=cF6>']'</span><span class=cF0>; </span><span class=cF2>//Border</span><span class=cF0>
|
||
|
<a name="l21"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
|
||
|
<a name="l22"></a> buf=r;
|
||
|
<a name="l23"></a> size=dst-r-2*BORDER_CHARS;
|
||
|
<a name="l24"></a>}
|
||
|
<a name="l25"></a>
|
||
|
<a name="l26"></a></span><span class=cF1>U0</span><span class=cF0> PDAnswer(</span><span class=cF1>U8</span><span class=cF0> *a,</span><span class=cF9>I64</span><span class=cF0> len)
|
||
|
<a name="l27"></a>{
|
||
|
<a name="l28"></a> </span><span class=cF5>DocLock</span><span class=cF0>(doc);
|
||
|
<a name="l29"></a> a-=(len-1)/2;
|
||
|
<a name="l30"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc,</span><span class=cF6>"CPU%02X Len:%2d "</span><span class=cF0>,</span><span class=cF5>Gs</span><span class=cF0>->num,len);
|
||
|
<a name="l31"></a> </span><span class=cF1>while</span><span class=cF0> (len--)
|
||
|
<a name="l32"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc,</span><span class=cF6>"%C"</span><span class=cF0>,*a++); </span><span class=cF2>//%C is toupper char</span><span class=cF0>
|
||
|
<a name="l33"></a> </span><span class=cF5>DocPrint</span><span class=cF0>(doc,</span><span class=cF6>"\n"</span><span class=cF0>);
|
||
|
<a name="l34"></a> </span><span class=cF5>DocUnlock</span><span class=cF0>(doc);
|
||
|
<a name="l35"></a>}
|
||
|
<a name="l36"></a>
|
||
|
<a name="l37"></a></span><span class=cF1>U0</span><span class=cF0> MPPalindrome(</span><span class=cF9>I64</span><span class=cF0> dummy=0)
|
||
|
<a name="l38"></a>{
|
||
|
<a name="l39"></a> </span><span class=cF1>no_warn</span><span class=cF0> dummy;
|
||
|
<a name="l40"></a> </span><span class=cF1>U8</span><span class=cF0> *src=buf+BORDER_CHARS+size*</span><span class=cF5>Gs</span><span class=cF0>->num/</span><span class=cFB>mp_cnt</span><span class=cF0>,
|
||
|
<a name="l41"></a> *f,*b;
|
||
|
<a name="l42"></a> </span><span class=cF9>I64</span><span class=cF0> len,best=0,
|
||
|
<a name="l43"></a> my_size=(size+</span><span class=cFB>mp_cnt</span><span class=cF0>-1)/</span><span class=cFB>mp_cnt</span><span class=cF0>;
|
||
|
<a name="l44"></a> </span><span class=cF1>while</span><span class=cF0> (my_size--) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l45"></a>
|
||
|
<a name="l46"></a> </span><span class=cF2>//Odd</span><span class=cF0>
|
||
|
<a name="l47"></a> f=src+1;
|
||
|
<a name="l48"></a> b=src-1;
|
||
|
<a name="l49"></a> </span><span class=cF1>while</span><span class=cF0> (*f==*b) {
|
||
|
<a name="l50"></a> f++;
|
||
|
<a name="l51"></a> b--;
|
||
|
<a name="l52"></a> }
|
||
|
<a name="l53"></a> len=f-b+1-2;
|
||
|
<a name="l54"></a> </span><span class=cF1>if</span><span class=cF0> (len>best) {
|
||
|
<a name="l55"></a> best=len;
|
||
|
<a name="l56"></a> PDAnswer(src,len);
|
||
|
<a name="l57"></a> }
|
||
|
<a name="l58"></a>
|
||
|
<a name="l59"></a> </span><span class=cF2>//Even</span><span class=cF0>
|
||
|
<a name="l60"></a> f=src+1;
|
||
|
<a name="l61"></a> b=src;
|
||
|
<a name="l62"></a> </span><span class=cF1>while</span><span class=cF0> (*f==*b) {
|
||
|
<a name="l63"></a> f++;
|
||
|
<a name="l64"></a> b--;
|
||
|
<a name="l65"></a> }
|
||
|
<a name="l66"></a> len=f-b+1-2;
|
||
|
<a name="l67"></a> </span><span class=cF1>if</span><span class=cF0> (len>best) {
|
||
|
<a name="l68"></a> best=len;
|
||
|
<a name="l69"></a> PDAnswer(src,len);
|
||
|
<a name="l70"></a> }
|
||
|
<a name="l71"></a>
|
||
|
<a name="l72"></a> src++;
|
||
|
<a name="l73"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l74"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&mp_not_done_flags,</span><span class=cF5>Gs</span><span class=cF0>->num);
|
||
|
<a name="l75"></a>}
|
||
|
<a name="l76"></a>
|
||
|
<a name="l77"></a></span><span class=cF1>U0</span><span class=cF0> Palindrome(</span><span class=cF1>U8</span><span class=cF0> *filename)
|
||
|
<a name="l78"></a>{
|
||
|
<a name="l79"></a> </span><span class=cF9>I64</span><span class=cF0> i;
|
||
|
<a name="l80"></a> </span><span class=cF1>F64</span><span class=cF0> t0=</span><span class=cF5>tS</span><span class=cF0>;
|
||
|
<a name="l81"></a>
|
||
|
<a name="l82"></a> buf=</span><span class=cF5>FileRead</span><span class=cF0>(filename,&size);
|
||
|
<a name="l83"></a> PDNormalize;
|
||
|
<a name="l84"></a>
|
||
|
<a name="l85"></a> doc=</span><span class=cF5>DocPut</span><span class=cF0>;
|
||
|
<a name="l86"></a> mp_not_done_flags=1<<</span><span class=cFB>mp_cnt</span><span class=cF0>-1;
|
||
|
<a name="l87"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<</span><span class=cFB>mp_cnt</span><span class=cF0>;i++)
|
||
|
<a name="l88"></a> </span><span class=cF5>JobQue</span><span class=cF0>(&MPPalindrome,</span><span class=cF3>NULL</span><span class=cF0>,i);
|
||
|
<a name="l89"></a> </span><span class=cF1>while</span><span class=cF0> (mp_not_done_flags)
|
||
|
<a name="l90"></a> </span><span class=cF5>Yield</span><span class=cF0>;
|
||
|
<a name="l91"></a>
|
||
|
<a name="l92"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
|
||
|
<a name="l93"></a> </span><span class=cF6>"Time:%9.5f\n"</span><span class=cF0>,</span><span class=cF5>tS</span><span class=cF0>-t0;
|
||
|
<a name="l94"></a>}
|
||
|
<a name="l95"></a>
|
||
|
<a name="l96"></a>Palindrome(</span><span class=cF3>BIBLE_FILENAME</span><span class=cF0>);
|
||
|
</span></pre></body>
|
||
|
</html>
|