TempleOSTS_130315.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:45:37 +02:00
1 parent e57428affb
commit 17b71f1a2d
958 files changed
+26043 -15907

No files matched your search

+155
View File
@@ -0,0 +1,155 @@
//This has a simple and fancy way of searching
//See ::/TempleOS/Apps/Vocabulary/VocabQuiz.CPP.Z
//for another example of dictionary usage.
#define NUM_ROWS 20
#define NUM_COLS 20
#define MAX_DIMENSION MaxI64(NUM_ROWS,NUM_COLS)
U8 m[NUM_ROWS][NUM_COLS];
U0 Init()
{
I64 x,y;
for (y=0;y<NUM_ROWS;y++)
for (x=0;x<NUM_COLS;x++)
m[y][x]='A'+RandU16%26;
}
U0 Display()
{
I64 x,y;
for (y=0;y<NUM_ROWS;y++) {
for (x=0;x<NUM_COLS;x++)
'' m[y][x];
NewLine;
}
}
U0 GetWord(U8 *dst,I64 x,I64 y,I64 dx,I64 dy)
{
while (0<=x<NUM_COLS && 0<=y<NUM_ROWS) {
*dst++=m[y][x];
y+=dy;
x+=dx;
}
*dst=0;
}
//////////////////////////////////////
U0 Search(I64 dx,I64 dy)
{
I64 x,y,i,n;
U8 buf[MAX_DIMENSION+1],*ptr;
for (y=0;y<NUM_ROWS;y++)
for (x=0;x<NUM_COLS;x++) {
GetWord(buf,x,y,dx,dy);
n=StrLen(buf);
for (i=n;i>2;i--) {
buf[i]=0;
if ((ptr=WSDPtAtWord(buf)) && *ptr++==WSD_WORD_CHAR &&
!StrICmp(ptr,buf)) {
"%s ",buf;
}
}
}
}
U0 SimpleWordSearch()
{
Search(1,0);
Search(0,1);
Search(-1,0);
Search(0,-1);
Search(1,1);
Search(-1,-1);
Search(1,-1);
Search(-1,1);
NewLine;
}
////////////////////////////////////////
U8 words[NUM_ROWS*NUM_COLS*8][MAX_DIMENSION+1];
U8 *word_ptrs[NUM_ROWS*NUM_COLS*8];
U0 CollectWords(I64 dx,I64 dy,I64 *_n)
{
I64 x,y,n=*_n;
for (y=0;y<NUM_ROWS;y++)
for (x=0;x<NUM_COLS;x++) {
GetWord(&words[n],x,y,dx,dy);
word_ptrs[n]=&words[n];
n++;
}
*_n=n;
}
I64 WordsCompare(U8 *e1,U8 *e2)
{
return StrCmp(e1,e2);
}
/*
Fmt of word lst entry:
U8 WSD_WORD_CHAR
U8 word[] with terminating zero
I16 block; //definition offset in ::/TempleOS/Adam/WordStat/WSDefs.DAT
*/
U0 DisplayWords(I64 n)
{
I64 i=0,k;
U8 *w1,*w2,*dict=ws_dict_word_lst;
for (i=0;i<n;i++)
while (*dict) {
w1=word_ptrs[i];
w2=dict+1;
while (*w2 && *w1==ToUpper(*w2)) {
w1++;
w2++;
}
if (ToUpper(*w2)>*w1)
break;
if (!*w2) {
if (StrLen(dict+1)>2) {
k=i;
while (k<n && !StrNICmp(word_ptrs[k++],dict+1,StrLen(dict+1)))
"%s ",dict+1;
}
w2=dict+1;
while (!StrICmp(w2,dict+1))
dict+=StrLen(dict+1)+4;
} else
dict+=StrLen(dict+1)+4;
}
}
U0 FancyWordSearch()
{
I64 n=0;
CollectWords(1,0,&n);
CollectWords(0,1,&n);
CollectWords(-1,0,&n);
CollectWords(0,-1,&n);
CollectWords(1,1,&n);
CollectWords(-1,-1,&n);
CollectWords(1,-1,&n);
CollectWords(-1,1,&n);
QSortI64(word_ptrs,n,&WordsCompare);
DisplayWords(n);
NewLine;
}
/////////////////////////////////////
U0 WordSearch()
{
Init;
Display;
NewLine;
SimpleWordSearch;
FancyWordSearch;
}
WordSearch;