ZealOS/docs/Demo/SuggestSpelling.ZC.html

138 lines
10 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">
2021-12-11 11:10:58 +00:00
<meta name="generator" content="ZealOS V1.07">
2021-07-03 05:07:57 +01:00
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
2021-07-03 05:07:57 +01:00
</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=cF2>/*This does a really crappy job of</span><span class=cF0>
<a name="l2"></a></span><span class=cF2>suggesting spellings. Write a better</span><span class=cF0>
<a name="l3"></a></span><span class=cF2>one for fun.</span><span class=cF0>
<a name="l4"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l5"></a>
<a name="l6"></a></span><span class=cF1>U8</span><span class=cF0> *SuggestMatchForm(</span><span class=cF1>U8</span><span class=cF0> *src)
<a name="l7"></a>{
<a name="l8"></a> </span><span class=cF9>I64</span><span class=cF0> ch, ch1 = </span><span class=cFE>0</span><span class=cF0>;
<a name="l9"></a> </span><span class=cF1>U8</span><span class=cF0> *res = </span><span class=cF5>MStrUtil</span><span class=cF0>(src, </span><span class=cF3>SUF_TO_UPPER</span><span class=cF0>), *dst;
2021-07-03 05:07:57 +01:00
<a name="l10"></a>
<a name="l11"></a> dst = src = res;
<a name="l12"></a> </span><span class=cF1>while</span><span class=cF0> (ch = *src++)
<a name="l13"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l14"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrOcc</span><span class=cF7>(</span><span class=cF6>&quot;AEIOU&quot;</span><span class=cF0>, ch</span><span class=cF7>)</span><span class=cF0>)
<a name="l15"></a> {
<a name="l16"></a> </span><span class=cF1>if</span><span class=cF0> (ch == </span><span class=cF6>'C'</span><span class=cF0>)
<a name="l17"></a> ch = </span><span class=cF6>'K'</span><span class=cF0>;
<a name="l18"></a> </span><span class=cF1>if</span><span class=cF0> (ch == </span><span class=cF6>'Z'</span><span class=cF0>)
<a name="l19"></a> ch = </span><span class=cF6>'S'</span><span class=cF0>;
<a name="l20"></a> </span><span class=cF1>if</span><span class=cF0> (ch != ch1) </span><span class=cF2>//double chars to single</span><span class=cF0>
<a name="l21"></a> *dst++ = ch;
<a name="l22"></a> }
<a name="l23"></a> ch1 = ch;
<a name="l24"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l25"></a> *dst = </span><span class=cFE>0</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l26"></a>
<a name="l27"></a> </span><span class=cF1>return</span><span class=cF0> res;
2021-07-03 05:07:57 +01:00
<a name="l28"></a>}
<a name="l29"></a>
<a name="l30"></a></span><span class=cF2>/*Format of word list entry:</span><span class=cF0>
<a name="l31"></a> </span><span class=cF2>U8 ACD_WORD_CHAR</span><span class=cF0>
<a name="l32"></a> </span><span class=cF2>U8 word[] with terminating zero</span><span class=cF0>
<a name="l33"></a> </span><span class=cF2>I16 block; //definition offset in ::/System/AutoComplete/ACDefs.DATA</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l34"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l35"></a>
<a name="l36"></a></span><span class=cF1>Bool</span><span class=cF0> SuggestSpelling(</span><span class=cF1>U8</span><span class=cF0> *word)
<a name="l37"></a>{
<a name="l38"></a> </span><span class=cF1>U8</span><span class=cF0> *dict = </span><span class=cFB>acd</span><span class=cF0>.word_list,
<a name="l39"></a> *pf = SuggestMatchForm(word),
<a name="l40"></a> *wf;
<a name="l41"></a> </span><span class=cF9>I64</span><span class=cF0> len = </span><span class=cF5>StrLen</span><span class=cF0>(pf),
<a name="l42"></a> num_cols = </span><span class=cF5>Fs</span><span class=cF0>-&gt;win_width / </span><span class=cFE>16</span><span class=cF0>,
<a name="l43"></a> col = </span><span class=cFE>0</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l44"></a>
<a name="l45"></a> </span><span class=cF1>if</span><span class=cF0> (len)
<a name="l46"></a> </span><span class=cF1>while</span><span class=cF0> (*dict)
<a name="l47"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l48"></a> wf = SuggestMatchForm(dict + </span><span class=cFE>1</span><span class=cF0>);
<a name="l49"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrNCompare</span><span class=cF7>(</span><span class=cF0>pf, wf, len</span><span class=cF7>)</span><span class=cF0>)
<a name="l50"></a> {
<a name="l51"></a> </span><span class=cF6>&quot;%16s&quot;</span><span class=cF0>, dict + </span><span class=cFE>1</span><span class=cF0>;
<a name="l52"></a> </span><span class=cF1>if</span><span class=cF0> (++col &gt;= num_cols)
<a name="l53"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l54"></a> col=</span><span class=cFE>0</span><span class=cF0>;
<a name="l55"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l56"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l57"></a> }
<a name="l58"></a> </span><span class=cF5>Free</span><span class=cF0>(wf);
<a name="l59"></a> dict += </span><span class=cF5>StrLen</span><span class=cF0>(dict + </span><span class=cFE>1</span><span class=cF0>) + </span><span class=cFE>4</span><span class=cF0>;
<a name="l60"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l61"></a> </span><span class=cF5>Free</span><span class=cF0>(pf);
<a name="l62"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l63"></a>
<a name="l64"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>ToBool</span><span class=cF0>(len);
2021-07-03 05:07:57 +01:00
<a name="l65"></a>}
<a name="l66"></a>
<a name="l67"></a></span><span class=cF1>U0</span><span class=cF0> SuggestSpellingDemo()
<a name="l68"></a>{
<a name="l69"></a> </span><span class=cF1>U8</span><span class=cF0> *w;
2021-07-03 05:07:57 +01:00
<a name="l70"></a>
<a name="l71"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l72"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l73"></a> w = </span><span class=cF5>StrGet</span><span class=cF0>(</span><span class=cF6>&quot;Word:&quot;</span><span class=cF0>);
<a name="l74"></a> </span><span class=cF1>if</span><span class=cF0> (*w) {
<a name="l75"></a> SuggestSpelling(w);
<a name="l76"></a> </span><span class=cF5>Free</span><span class=cF0>(w);
<a name="l77"></a> }
<a name="l78"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l79"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l80"></a> </span><span class=cF7>}</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l81"></a>}
<a name="l82"></a>
<a name="l83"></a></span><span class=cF2>//If you &quot;System Include&quot; this file, it will</span><span class=cF0>
<a name="l84"></a></span><span class=cF2>//install this command as a hot-key.</span><span class=cF0>
<a name="l85"></a>
<a name="l86"></a></span><span class=cF1>U0</span><span class=cF0> CtrlAltL(</span><span class=cF9>I64</span><span class=cF0>)
<a name="l87"></a>{
<a name="l88"></a></span><span class=cF2>//</span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l1627"><span class=cF4>ac.cur_word</span></a><span class=cF2> is only set if AutoComplete</span><span class=cF0>
<a name="l89"></a> </span><span class=cF2>//is running.</span><span class=cF0>
<a name="l90"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>TaskValidate</span><span class=cF7>(</span><span class=cFB>ac</span><span class=cF0>.task</span><span class=cF7>)</span><span class=cF0>)
<a name="l91"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l92"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
<a name="l93"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>500</span><span class=cF0>);
<a name="l94"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l95"></a> </span><span class=cF5>PopUp</span><span class=cF0>(</span><span class=cF6>&quot;if (SuggestSpelling(ac.cur_word)) View;&quot;</span><span class=cF0>);
2021-07-03 05:07:57 +01:00
<a name="l96"></a>}
<a name="l97"></a>
<a name="l98"></a></span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Fs</span><span class=cF0> != </span><span class=cFB>sys_task</span><span class=cF0>)
<a name="l99"></a> SuggestSpellingDemo;
2021-07-03 05:07:57 +01:00
<a name="l100"></a></span><span class=cF1>else</span><span class=cF0>
<a name="l101"></a>{
<a name="l102"></a> </span><span class=cF5>CtrlAltCBSet</span><span class=cF0>(</span><span class=cF6>'L'</span><span class=cF0>, &amp;CtrlAltL, </span><span class=cF6>&quot;Cmd /Suggest Spelling&quot;</span><span class=cF0>);
2021-07-03 05:07:57 +01:00
<a name="l103"></a></span><span class=cF2>//Appears in the System Task Window</span><span class=cF0>
<a name="l104"></a> </span><span class=cF6>&quot;&lt;CTRL-ALT-l&gt; installed\n&quot;</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l105"></a>}
<a name="l106"></a>
<a name="l107"></a></span><span class=cF2>//Note: It would be more appropriate</span><span class=cF0>
2021-12-11 11:10:58 +00:00
<a name="l108"></a></span><span class=cF2>//to define a key in </span><a href="https://zeal-operating-system.github.io/ZealOS/Home/HomeKeyPlugIns.ZC.html#l11"><span class=cF4>MyPutKey</span></a><span class=cF2>().</span><span class=cF0>
2021-07-03 05:07:57 +01:00
</span></pre></body>
</html>