185 lines
12 KiB
HTML
Executable File
185 lines
12 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=cF2>//Simple and fancy way of searching</span><span class=cF0>
|
|
<a name="l2"></a>
|
|
<a name="l3"></a></span><span class=cF2>//See ::/Apps/Vocabulary/VocabQuiz.HC.Z</span><span class=cF0>
|
|
<a name="l4"></a></span><span class=cF2>//for another example of dictionary usage.</span><span class=cF0>
|
|
<a name="l5"></a>
|
|
<a name="l6"></a>#</span><span class=cF1>define</span><span class=cF0> ROWS_NUM 20
|
|
<a name="l7"></a>#</span><span class=cF1>define</span><span class=cF0> COLS_NUM 20
|
|
<a name="l8"></a>#</span><span class=cF1>define</span><span class=cF0> DIM_MAX </span><span class=cF5>MaxI64</span><span class=cF0>(ROWS_NUM,COLS_NUM)
|
|
<a name="l9"></a>
|
|
<a name="l10"></a></span><span class=cF1>U8</span><span class=cF0> m[ROWS_NUM][COLS_NUM];
|
|
<a name="l11"></a>
|
|
<a name="l12"></a></span><span class=cF1>U0</span><span class=cF0> Init()
|
|
<a name="l13"></a>{
|
|
<a name="l14"></a> </span><span class=cF9>I64</span><span class=cF0> x,y;
|
|
<a name="l15"></a> </span><span class=cF1>for</span><span class=cF0> (y=0;y<ROWS_NUM;y++)
|
|
<a name="l16"></a> </span><span class=cF1>for</span><span class=cF0> (x=0;x<COLS_NUM;x++)
|
|
<a name="l17"></a> m[y][x]=</span><span class=cF6>'A'</span><span class=cF0>+</span><span class=cF5>RandU16</span><span class=cF0>%26;
|
|
<a name="l18"></a>}
|
|
<a name="l19"></a>
|
|
<a name="l20"></a></span><span class=cF1>U0</span><span class=cF0> Display()
|
|
<a name="l21"></a>{
|
|
<a name="l22"></a> </span><span class=cF9>I64</span><span class=cF0> x,y;
|
|
<a name="l23"></a> </span><span class=cF1>for</span><span class=cF0> (y=0;y<ROWS_NUM;y++) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l24"></a> </span><span class=cF1>for</span><span class=cF0> (x=0;x<COLS_NUM;x++)
|
|
<a name="l25"></a> </span><span class=cF6>''</span><span class=cF0> m[y][x];
|
|
<a name="l26"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
|
|
<a name="l27"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l28"></a>}
|
|
<a name="l29"></a>
|
|
<a name="l30"></a></span><span class=cF1>U0</span><span class=cF0> GetWord(</span><span class=cF1>U8</span><span class=cF0> *dst,</span><span class=cF9>I64</span><span class=cF0> x,</span><span class=cF9>I64</span><span class=cF0> y,</span><span class=cF9>I64</span><span class=cF0> dx,</span><span class=cF9>I64</span><span class=cF0> dy)
|
|
<a name="l31"></a>{
|
|
<a name="l32"></a> </span><span class=cF1>while</span><span class=cF0> (0<=x<COLS_NUM && 0<=y<ROWS_NUM) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l33"></a> *dst++=m[y][x];
|
|
<a name="l34"></a> y+=dy;
|
|
<a name="l35"></a> x+=dx;
|
|
<a name="l36"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l37"></a> *dst=0;
|
|
<a name="l38"></a>}
|
|
<a name="l39"></a>
|
|
<a name="l40"></a></span><span class=cF2>//************************************</span><span class=cF0>
|
|
<a name="l41"></a></span><span class=cF1>U0</span><span class=cF0> Search(</span><span class=cF9>I64</span><span class=cF0> dx,</span><span class=cF9>I64</span><span class=cF0> dy)
|
|
<a name="l42"></a>{
|
|
<a name="l43"></a> </span><span class=cF9>I64</span><span class=cF0> x,y,i,n;
|
|
<a name="l44"></a> </span><span class=cF1>U8</span><span class=cF0> buf[DIM_MAX+1],*ptr;
|
|
<a name="l45"></a> </span><span class=cF1>for</span><span class=cF0> (y=0;y<ROWS_NUM;y++)
|
|
<a name="l46"></a> </span><span class=cF1>for</span><span class=cF0> (x=0;x<COLS_NUM;x++) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l47"></a> GetWord(buf,x,y,dx,dy);
|
|
<a name="l48"></a> n=</span><span class=cF5>StrLen</span><span class=cF0>(buf);
|
|
<a name="l49"></a> </span><span class=cF1>for</span><span class=cF0> (i=n;i>2;i--) {
|
|
<a name="l50"></a> buf[i]=0;
|
|
<a name="l51"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>ptr=</span><span class=cF5>ACDWordPtAt</span><span class=cF0>(buf)</span><span class=cF7>)</span><span class=cF0> && *ptr++==</span><span class=cF3>ACD_WORD_CHAR</span><span class=cF0> &&
|
|
<a name="l52"></a> !</span><span class=cF5>StrICmp</span><span class=cF7>(</span><span class=cF0>ptr,buf</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l53"></a> </span><span class=cF6>"%s "</span><span class=cF0>,buf;
|
|
<a name="l54"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l55"></a> }
|
|
<a name="l56"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l57"></a>}
|
|
<a name="l58"></a>
|
|
<a name="l59"></a></span><span class=cF1>U0</span><span class=cF0> SimpleWordSearch()
|
|
<a name="l60"></a>{
|
|
<a name="l61"></a> Search(1,0);
|
|
<a name="l62"></a> Search(0,1);
|
|
<a name="l63"></a> Search(-1,0);
|
|
<a name="l64"></a> Search(0,-1);
|
|
<a name="l65"></a> Search(1,1);
|
|
<a name="l66"></a> Search(-1,-1);
|
|
<a name="l67"></a> Search(1,-1);
|
|
<a name="l68"></a> Search(-1,1);
|
|
<a name="l69"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
|
|
<a name="l70"></a>}
|
|
<a name="l71"></a>
|
|
<a name="l72"></a></span><span class=cF2>//************************************</span><span class=cF0>
|
|
<a name="l73"></a></span><span class=cF1>U8</span><span class=cF0> words[ROWS_NUM*COLS_NUM*8][DIM_MAX+1];
|
|
<a name="l74"></a></span><span class=cF1>U8</span><span class=cF0> *word_ptrs[ROWS_NUM*COLS_NUM*8];
|
|
<a name="l75"></a>
|
|
<a name="l76"></a></span><span class=cF1>U0</span><span class=cF0> CollectWords(</span><span class=cF9>I64</span><span class=cF0> dx,</span><span class=cF9>I64</span><span class=cF0> dy,</span><span class=cF9>I64</span><span class=cF0> *_n)
|
|
<a name="l77"></a>{
|
|
<a name="l78"></a> </span><span class=cF9>I64</span><span class=cF0> x,y,n=*_n;
|
|
<a name="l79"></a> </span><span class=cF1>for</span><span class=cF0> (y=0;y<ROWS_NUM;y++)
|
|
<a name="l80"></a> </span><span class=cF1>for</span><span class=cF0> (x=0;x<COLS_NUM;x++) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l81"></a> GetWord(&words[n],x,y,dx,dy);
|
|
<a name="l82"></a> word_ptrs[n]=&words[n];
|
|
<a name="l83"></a> n++;
|
|
<a name="l84"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l85"></a> *_n=n;
|
|
<a name="l86"></a>}
|
|
<a name="l87"></a>
|
|
<a name="l88"></a></span><span class=cF9>I64</span><span class=cF0> WordsCompare(</span><span class=cF1>U8</span><span class=cF0> *e1,</span><span class=cF1>U8</span><span class=cF0> *e2)
|
|
<a name="l89"></a>{
|
|
<a name="l90"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>StrCmp</span><span class=cF0>(e1,e2);
|
|
<a name="l91"></a>}
|
|
<a name="l92"></a>
|
|
<a name="l93"></a></span><span class=cF2>/*Fmt of word lst entry:</span><span class=cF0>
|
|
<a name="l94"></a></span><span class=cF2> U8 ACD_WORD_CHAR</span><span class=cF0>
|
|
<a name="l95"></a></span><span class=cF2> U8 word[] with terminating zero</span><span class=cF0>
|
|
<a name="l96"></a></span><span class=cF2> I16 block; //definition offset in ::/Adam/AutoComplete/ACDefs.DATA</span><span class=cF0>
|
|
<a name="l97"></a></span><span class=cF2>*/</span><span class=cF0>
|
|
<a name="l98"></a>
|
|
<a name="l99"></a></span><span class=cF1>U0</span><span class=cF0> DisplayWords(</span><span class=cF9>I64</span><span class=cF0> n)
|
|
<a name="l100"></a>{
|
|
<a name="l101"></a> </span><span class=cF9>I64</span><span class=cF0> i=0,k;
|
|
<a name="l102"></a> </span><span class=cF1>U8</span><span class=cF0> *w1,*w2,*dict=</span><span class=cFB>acd</span><span class=cF0>.word_lst;
|
|
<a name="l103"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<n;i++)
|
|
<a name="l104"></a> </span><span class=cF1>while</span><span class=cF0> (*dict) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l105"></a> w1=word_ptrs[i];
|
|
<a name="l106"></a> w2=dict+1;
|
|
<a name="l107"></a> </span><span class=cF1>while</span><span class=cF0> (*w2 && *w1==</span><span class=cF5>ToUpper</span><span class=cF7>(</span><span class=cF0>*w2</span><span class=cF7>)</span><span class=cF0>) {
|
|
<a name="l108"></a> w1++;
|
|
<a name="l109"></a> w2++;
|
|
<a name="l110"></a> }
|
|
<a name="l111"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>ToUpper</span><span class=cF7>(</span><span class=cF0>*w2</span><span class=cF7>)</span><span class=cF0>>*w1)
|
|
<a name="l112"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l113"></a> </span><span class=cF1>if</span><span class=cF0> (!*w2) {
|
|
<a name="l114"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrLen</span><span class=cF7>(</span><span class=cF0>dict+1</span><span class=cF7>)</span><span class=cF0>>2) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l115"></a> k=i;
|
|
<a name="l116"></a> </span><span class=cF1>while</span><span class=cF0> (k<n && !</span><span class=cF5>StrNICmp</span><span class=cF7>(</span><span class=cF0>word_ptrs[k++],dict+1,</span><span class=cF5>StrLen</span><span class=cF0>(dict+1)</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l117"></a> </span><span class=cF6>"%s "</span><span class=cF0>,dict+1;
|
|
<a name="l118"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l119"></a> w2=dict+1;
|
|
<a name="l120"></a> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cF5>StrICmp</span><span class=cF7>(</span><span class=cF0>w2,dict+1</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l121"></a> dict+=</span><span class=cF5>StrLen</span><span class=cF0>(dict+1)+4;
|
|
<a name="l122"></a> } </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l123"></a> dict+=</span><span class=cF5>StrLen</span><span class=cF0>(dict+1)+4;
|
|
<a name="l124"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l125"></a>}
|
|
<a name="l126"></a>
|
|
<a name="l127"></a></span><span class=cF1>U0</span><span class=cF0> FancyWordSearch()
|
|
<a name="l128"></a>{
|
|
<a name="l129"></a> </span><span class=cF9>I64</span><span class=cF0> n=0;
|
|
<a name="l130"></a> CollectWords(1,0,&n);
|
|
<a name="l131"></a> CollectWords(0,1,&n);
|
|
<a name="l132"></a> CollectWords(-1,0,&n);
|
|
<a name="l133"></a> CollectWords(0,-1,&n);
|
|
<a name="l134"></a> CollectWords(1,1,&n);
|
|
<a name="l135"></a> CollectWords(-1,-1,&n);
|
|
<a name="l136"></a> CollectWords(1,-1,&n);
|
|
<a name="l137"></a> CollectWords(-1,1,&n);
|
|
<a name="l138"></a> </span><span class=cF5>QSortI64</span><span class=cF0>(word_ptrs,n,&WordsCompare);
|
|
<a name="l139"></a> DisplayWords(n);
|
|
<a name="l140"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
|
|
<a name="l141"></a>}
|
|
<a name="l142"></a>
|
|
<a name="l143"></a></span><span class=cF2>//************************************</span><span class=cF0>
|
|
<a name="l144"></a></span><span class=cF1>U0</span><span class=cF0> WordSearch()
|
|
<a name="l145"></a>{
|
|
<a name="l146"></a> Init;
|
|
<a name="l147"></a> Display;
|
|
<a name="l148"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
|
|
<a name="l149"></a> SimpleWordSearch;
|
|
<a name="l150"></a> FancyWordSearch;
|
|
<a name="l151"></a>}
|
|
<a name="l152"></a>
|
|
<a name="l153"></a>WordSearch;
|
|
</span></pre></body>
|
|
</html>
|