TempleOSTS_140317.ISO
This commit is contained in:
1 parent
2d2a65d572
commit
7ef616a20e
1416 files changed
+223873
-53917
No files matched your search
Binary file not shown.
@@ -0,0 +1,304 @@
|
||||
#help_index "WordStat/Dictionary"
|
||||
|
||||
public U0 WSDWordsLoad()
|
||||
{
|
||||
I64 size;
|
||||
CHashGeneric *temph;
|
||||
U8 *in_ptr,*in_start,*st2;
|
||||
U16 *d;
|
||||
ws_dict_num_words=0;
|
||||
if (in_ptr=FileRead(WSD_WORD_FILENAME,&size)) {
|
||||
in_start=in_ptr;
|
||||
Free(ws_dict_word_lst);
|
||||
ws_dict_word_lst=AMAlloc(size);
|
||||
MemCpy(ws_dict_word_lst,in_start,size);
|
||||
ws_dict_word_lst_size=size;
|
||||
|
||||
while (in_ptr<in_start+size) {
|
||||
if (*in_ptr==WSD_WORD_CHAR)
|
||||
in_ptr++;
|
||||
if (*in_ptr) {
|
||||
st2=MStrUtil(in_ptr,SUF_TO_UPPER);
|
||||
temph=ACAlloc(sizeof(CHashGeneric)+StrLen(st2)+1);
|
||||
StrCpy(temph+1,st2);
|
||||
Free(st2);
|
||||
in_ptr+=StrLen(in_ptr)+1;
|
||||
temph->str=temph+1;
|
||||
temph->use_cnt=1;
|
||||
temph->type=HTT_DICT_WORD;
|
||||
d=in_ptr;
|
||||
temph->user_data0=*d;
|
||||
in_ptr+=2;
|
||||
HashAdd(temph,ws_hash_table);
|
||||
ws_dict_num_words++;
|
||||
} else
|
||||
in_ptr+=3;
|
||||
}
|
||||
Free(in_start);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public U8 *WSDGetDef(U8 *st,I64 def_num=1)
|
||||
{
|
||||
CFile *f;
|
||||
CHashGeneric *temph;
|
||||
U8 *result=NULL,*buf,*in_ptr,
|
||||
*st2=MStrUtil(st,SUF_TO_UPPER);
|
||||
temph=HashFind(st2,ws_hash_table,HTT_DICT_WORD);
|
||||
Free(st2);
|
||||
if (temph) {
|
||||
if (f=FOpen(WSD_DEF_FILENAME,"r")) {
|
||||
buf=MAlloc(WSD_BLK_SIZE*2+1);
|
||||
buf[WSD_BLK_SIZE*2]=0; //terminate
|
||||
FRBlks(f,buf,temph->user_data0*WSD_BLK_SIZE/BLK_SIZE,WSD_BLK_SIZE*2/BLK_SIZE);
|
||||
FClose(f);
|
||||
in_ptr=buf;
|
||||
while (in_ptr<buf+WSD_BLK_SIZE*2) {
|
||||
while (*in_ptr!=WSD_WORD_CHAR && in_ptr<buf+WSD_BLK_SIZE*2)
|
||||
in_ptr++;
|
||||
if (*in_ptr++==WSD_WORD_CHAR) {
|
||||
if (!StrICmp(st,in_ptr)) {
|
||||
while (def_num && *in_ptr!=WSD_WORD_CHAR
|
||||
&& in_ptr<buf+WSD_BLK_SIZE*2) {
|
||||
if (*in_ptr==WSD_DEF_CHAR) {
|
||||
if (!--def_num)
|
||||
break;
|
||||
else
|
||||
in_ptr++;
|
||||
} else
|
||||
in_ptr++;
|
||||
}
|
||||
if (*in_ptr++==WSD_DEF_CHAR) {
|
||||
result=StrNew(in_ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Free(buf);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public U8 *WSDGetWord(U8 *st)
|
||||
{
|
||||
CFile *f;
|
||||
CHashGeneric *temph;
|
||||
U8 *result=NULL,*buf,*in_ptr,*in_ptr2,
|
||||
*st2=MStrUtil(st,SUF_TO_UPPER);
|
||||
temph=HashFind(st2,ws_hash_table,HTT_DICT_WORD);
|
||||
Free(st2);
|
||||
if (temph) {
|
||||
if (f=FOpen(WSD_DEF_FILENAME,"r")) {
|
||||
buf=MAlloc(WSD_BLK_SIZE*2+1);
|
||||
buf[WSD_BLK_SIZE*2]=0; //terminate
|
||||
FRBlks(f,buf,temph->user_data0*WSD_BLK_SIZE/BLK_SIZE,WSD_BLK_SIZE*2/BLK_SIZE);
|
||||
FClose(f);
|
||||
in_ptr=buf;
|
||||
while (in_ptr<buf+WSD_BLK_SIZE*2) {
|
||||
while (*in_ptr!=WSD_WORD_CHAR && in_ptr<buf+WSD_BLK_SIZE*2)
|
||||
in_ptr++;
|
||||
if (*in_ptr++==WSD_WORD_CHAR) {
|
||||
if (!StrICmp(st,in_ptr)) {
|
||||
in_ptr2=in_ptr;
|
||||
in_ptr--;
|
||||
while (*in_ptr2!=WSD_WORD_CHAR
|
||||
&& in_ptr2<buf+WSD_BLK_SIZE*2) {
|
||||
in_ptr2++;
|
||||
}
|
||||
result=MAlloc(in_ptr2+1-in_ptr);
|
||||
MemCpy(result,in_ptr,in_ptr2-in_ptr);
|
||||
result[in_ptr2-in_ptr]=WSD_END_CHAR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Free(buf);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Fmt of word lst entry:
|
||||
U8 WSD_WORD_CHAR
|
||||
U8 word[] with terminating zero
|
||||
I16 block;
|
||||
*/
|
||||
public U8 *WSDPtAtWord(U8 *st)
|
||||
{
|
||||
I64 i;
|
||||
U8 *start=ws_dict_word_lst,*r=start,
|
||||
*end=ws_dict_word_lst+ws_dict_word_lst_size;
|
||||
if (!st || !*st)
|
||||
return ws_dict_word_lst;
|
||||
if (ws_dict_word_lst_size) {
|
||||
while (start+3<end) {
|
||||
r=(start+end)>>1;
|
||||
while (TRUE) {
|
||||
while (*r!=WSD_WORD_CHAR && r>ws_dict_word_lst)
|
||||
r--;
|
||||
if ((r[2]==WSD_WORD_CHAR||r[1]==WSD_WORD_CHAR)&&r-3>ws_dict_word_lst)
|
||||
r--;
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (*r==WSD_WORD_CHAR) {
|
||||
i=StrICmp(st,r+1);
|
||||
if (i<0)
|
||||
end=r-1;
|
||||
else if (i>0)
|
||||
start=r+StrLen(r)+3;
|
||||
else
|
||||
return r;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
r=(start+end)>>1;
|
||||
while (TRUE) {
|
||||
while (*r!=WSD_WORD_CHAR && r>ws_dict_word_lst)
|
||||
r--;
|
||||
if ((r[2]==WSD_WORD_CHAR||r[1]==WSD_WORD_CHAR)&&r-3>ws_dict_word_lst)
|
||||
r--;
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (*r==WSD_WORD_CHAR && StrICmp(st,r+1)>0)
|
||||
r+=StrLen(r)+3;
|
||||
}
|
||||
if (*r==WSD_WORD_CHAR)
|
||||
return r;
|
||||
else
|
||||
return ws_dict_word_lst;
|
||||
}
|
||||
|
||||
|
||||
U0 WSDDictWordsAdd(CDoc *doc,U8 *st=NULL)
|
||||
{
|
||||
I64 i;
|
||||
U8 *ptr;
|
||||
if (!st)
|
||||
st=ws_cur_word;
|
||||
if (st && (ptr=WSDPtAtWord(st))) {
|
||||
for (i=0;i<WSD_MAX_FILLINS;i++) {
|
||||
if (*ptr++!=WSD_WORD_CHAR)
|
||||
break;
|
||||
if (i)
|
||||
DocPrint(doc,"\n");
|
||||
wsd_fillins[i]=ptr-1;
|
||||
DocPrint(doc,"'%d' %s",i,ptr);
|
||||
ptr+=StrLen(ptr)+3;
|
||||
}
|
||||
wsd_num_fillins=i;
|
||||
}
|
||||
}
|
||||
|
||||
U0 WSDFillin(I64 n)
|
||||
{
|
||||
U8 *s;
|
||||
I64 len;
|
||||
if (0<=n<wsd_num_fillins) {
|
||||
s=wsd_fillins[n]+1;
|
||||
len=StrLen(s);
|
||||
if (len>ws_partial_len)
|
||||
Auto(s+ws_partial_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public U0 WSDDisplayDefs(CDoc *doc,U8 *st,I64 num=-1)
|
||||
{
|
||||
U8 *st2,*st3;
|
||||
I64 ch,i=0;
|
||||
if (!st) return;
|
||||
if (*st==WSD_WORD_CHAR)
|
||||
st++;
|
||||
DocPrint(doc,"$$WW,1$$$$RED$$%s:$$FG$$\n\n",st);
|
||||
if (num<0) {
|
||||
if (st3=WSDGetWord(st)) {
|
||||
st2=st3;
|
||||
while (ch=*st2++) {
|
||||
switch (ch) {
|
||||
case WSD_WORD_CHAR:
|
||||
break;
|
||||
case WSD_DEF_CHAR:
|
||||
DocPrint(doc,"$$GREEN$$(%d)$$FG$$ %s\n",
|
||||
++i,st2);
|
||||
break;
|
||||
case WSD_PRONUNCIATION_CHAR:
|
||||
DocPrint(doc,"$$LTGREEN$$%s$$FG$$\n",st2);
|
||||
break;
|
||||
case WSD_POS_CHAR:
|
||||
DocPrint(doc,"$$BLACK$$%s$$FG$$\n",st2);
|
||||
break;
|
||||
case WSD_EXTRA_CHAR:
|
||||
DocPrint(doc,"$$LTBLUE$$%s$$FG$$\n",st2);
|
||||
break;
|
||||
}
|
||||
st2+=StrLen(st2)+1;
|
||||
}
|
||||
Free(st3);
|
||||
}
|
||||
} else {
|
||||
while (st2=WSDGetDef(st,++i)) {
|
||||
if (i==num)
|
||||
DocPrint(doc,"$$GREEN$$(%d)$$FG$$ %s\n",
|
||||
i,st2);
|
||||
Free(st2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 WSDPopUpDef(U8 *st,I64 num=-1,CTask *parent=NULL)
|
||||
{
|
||||
U8 *buf;
|
||||
buf=MPrint("WSDDisplayDefs(DocPut,\"%s\",%d);View;",st,num);
|
||||
PopUp(buf,parent);
|
||||
Free(buf);
|
||||
}
|
||||
|
||||
U0 WSDDef(I64 n,CTask *parent=NULL)
|
||||
{
|
||||
if (0<=n<wsd_num_fillins)
|
||||
WSDPopUpDef(wsd_fillins[n],-1,parent);
|
||||
}
|
||||
|
||||
U0 WSFindMisspelled(CDoc *doc)
|
||||
{
|
||||
Bool unlock=DocLock(doc);
|
||||
CDocEntry *doc_e=doc->cur_entry;
|
||||
I64 col=doc->cur_data_col,col2,ch;
|
||||
do {
|
||||
if (doc_e!=doc && doc_e->flags1&DOCEF1_TAG) {
|
||||
while (col<doc_e->max_col) {
|
||||
while (col<doc_e->max_col && !Bt(chars_bitmap_word,doc_e->tag[col]))
|
||||
col++;
|
||||
if (col<doc_e->max_col) {
|
||||
col2=col;
|
||||
while (col2<doc_e->max_col && Bt(chars_bitmap_word,doc_e->tag[col2]))
|
||||
col2++;
|
||||
ch=doc_e->tag[col2];
|
||||
doc_e->tag[col2]=0;
|
||||
if (StrICmp(&doc_e->tag[col],WSDPtAtWord(&doc_e->tag[col])+1)) {
|
||||
doc_e->tag[col2]=ch;
|
||||
doc->cur_entry=doc_e;
|
||||
doc->cur_data_col=col;
|
||||
goto fm_done;
|
||||
}
|
||||
doc_e->tag[col2]=ch;
|
||||
col=col2;
|
||||
}
|
||||
}
|
||||
}
|
||||
doc_e=doc_e->next;
|
||||
col=doc_e->min_col;
|
||||
} while (doc_e!=doc->cur_entry);
|
||||
fm_done:
|
||||
if (unlock)
|
||||
DocUnlock(doc);
|
||||
}
|
||||
|
||||
#help_index ""
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
This file is a stand-alone program
|
||||
which will regenerate processed dictionary
|
||||
files from a raw Project Gutenberg
|
||||
dictionary file.
|
||||
|
||||
Supply the raw dictionary filename in
|
||||
the call at the bottom of this file
|
||||
and #include this file.
|
||||
|
||||
I ran $LK,"::/Misc/Dollar.CPP"$ on it, first.
|
||||
|
||||
See $LK,"::/Doc/Acknowledgements.TXT"$.
|
||||
*/
|
||||
|
||||
I64 WSDNextCmd(U8 **_ptr)
|
||||
{
|
||||
U8 ch,*ptr=*_ptr,*ptr2;
|
||||
I64 result=-1;
|
||||
do {
|
||||
do {
|
||||
if (!(ch=*ptr++)) goto ncmd_done;
|
||||
} while (ch!='<');
|
||||
|
||||
ptr2=ptr;
|
||||
do {
|
||||
if (!(ch=*ptr2++)) goto ncmd_done;
|
||||
} while (ch!='>');
|
||||
*--ptr2=0;
|
||||
result=LstMatch(ptr,"h1\0/h1\0def\0/def\0hw\0/hw\0tt\0/tt\0"
|
||||
"ety\0@fld\0@cd\0@blockquote\0@wordforms\0@note\0@altname\0@chform\0@cref\0@syn\0"
|
||||
"/ety\0@/fld\0@/cd\0@/blockquote\0@/wordforms\0@/note\0@/altname\0@/chform\0@/cref\0@/syn\0");
|
||||
*ptr2++='>';
|
||||
ptr=ptr2;
|
||||
} while (result<0);
|
||||
|
||||
ncmd_done:
|
||||
*_ptr=ptr;
|
||||
return result;
|
||||
}
|
||||
|
||||
U8 *WSDNextEntry(U8 **_ptr)
|
||||
{
|
||||
U8 *result,*ignore,ch,*ptr=*_ptr,buf[WSD_BLK_SIZE],*out_ptr=buf;
|
||||
I64 l;
|
||||
while (TRUE) {
|
||||
while (TRUE) {
|
||||
if (!(ch=*ptr++)) goto nentry_done;
|
||||
if (ch!='<') {
|
||||
*out_ptr++=ch;
|
||||
if (ch=='$$')
|
||||
*out_ptr++=ch;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
ignore="b>\0i>\0p>\0/b>\0/i>\0/p>\0"
|
||||
"ets>\0col>\0spn>\0/ets>\0/col>\0/spn>\0er>\0as>\0cs>\0cd>\0ex>\0"
|
||||
"/er>\0/as>\0/cs>\0/cd>\0/ex>\0"
|
||||
"note>\0/note>\0blockquote>\0/blockquote>\0";
|
||||
while (*ignore) {
|
||||
l=StrLen(ignore);
|
||||
if (!StrNCmp(ptr,ignore,l)) {
|
||||
ptr+=l;
|
||||
break;
|
||||
} else
|
||||
ignore+=l+1;
|
||||
}
|
||||
if (!*ignore)
|
||||
break;
|
||||
}
|
||||
nentry_done:
|
||||
*out_ptr++=0;
|
||||
result=StrNew(buf);
|
||||
*_ptr=ptr-1;
|
||||
return result;
|
||||
}
|
||||
|
||||
I64 WSDCompareWords(U8 *e1,U8 *e2)
|
||||
{
|
||||
return StrICmp(e1,e2);
|
||||
}
|
||||
|
||||
U8 *WSDSortWords(U8 *start,I64 size,I64 word_cnt)
|
||||
{
|
||||
U8 **ptr_array=MAlloc(sizeof(U8 *)*word_cnt),
|
||||
*out_start=MAlloc(size),
|
||||
*ptr=start,*ptr2;
|
||||
I64 i=0;
|
||||
while (*ptr) {
|
||||
ptr_array[i++]=ptr;
|
||||
ptr+=StrLen(ptr)+3;
|
||||
}
|
||||
"Sorting...\n"; Sleep(100);
|
||||
QSortI64(ptr_array,word_cnt,&WSDCompareWords);
|
||||
"Done...\n"; Sleep(100);
|
||||
|
||||
ptr=out_start;
|
||||
for (i=0;i<word_cnt;i++) {
|
||||
ptr2=ptr_array[i];
|
||||
while (*ptr2)
|
||||
*ptr++=*ptr2++;
|
||||
*ptr++=*ptr2++; //zero
|
||||
*ptr++=*ptr2++; //blk lo
|
||||
*ptr++=*ptr2++; //blk hi
|
||||
}
|
||||
*ptr++=0;
|
||||
return out_start;
|
||||
}
|
||||
|
||||
|
||||
U0 WSDGen(U8 *raw_dict_filename)
|
||||
{
|
||||
I64 cmd,size,word_cnt=0,largest_entry=0;
|
||||
U8 *st,*in_ptr=FileRead(raw_dict_filename,&size),*in_start=in_ptr,
|
||||
*out_ptr=MAlloc(size),*out_start=out_ptr,
|
||||
*word_ptr=MAlloc(size),*word_start=word_ptr,
|
||||
*last_word="",*def_word_start=out_ptr,
|
||||
*sorted_word_start;
|
||||
U16 *d;
|
||||
if (!in_ptr) return;
|
||||
do {
|
||||
cmd=WSDNextCmd(&in_ptr);
|
||||
if (cmd==WSD_H1) {
|
||||
next_word:
|
||||
if (out_ptr-def_word_start>largest_entry)
|
||||
largest_entry=out_ptr-def_word_start;
|
||||
def_word_start=out_ptr;
|
||||
if (st=WSDNextEntry(&in_ptr)) {
|
||||
if (*st) {
|
||||
if (StrICmp(st,last_word)) {
|
||||
word_cnt++;
|
||||
|
||||
*word_ptr++=WSD_WORD_CHAR;
|
||||
last_word=word_ptr;
|
||||
StrCpy(word_ptr,st);
|
||||
word_ptr+=StrLen(st)+1;
|
||||
|
||||
d=word_ptr;
|
||||
*d=(out_ptr-out_start)/WSD_BLK_SIZE;
|
||||
word_ptr+=2;
|
||||
|
||||
*out_ptr++=WSD_WORD_CHAR;
|
||||
StrCpy(out_ptr,st);
|
||||
out_ptr+=StrLen(st)+1;
|
||||
}
|
||||
Free(st);
|
||||
|
||||
do {
|
||||
do {
|
||||
cmd=WSDNextCmd(&in_ptr);
|
||||
if (cmd==WSD_H1)
|
||||
goto next_word;
|
||||
} while (cmd>=0 && !(cmd==WSD_DEF||cmd==WSD_PRONUNCIATION||cmd==WSD_POS||cmd==WSD_EXTRA));
|
||||
if (cmd==WSD_DEF) {
|
||||
if(st=WSDNextEntry(&in_ptr)) {
|
||||
if (*st) {
|
||||
*out_ptr++=WSD_DEF_CHAR;
|
||||
StrCpy(out_ptr,st);
|
||||
out_ptr+=StrLen(st)+1;
|
||||
}
|
||||
Free(st);
|
||||
}
|
||||
} else if (cmd==WSD_PRONUNCIATION) {
|
||||
if(st=WSDNextEntry(&in_ptr)) {
|
||||
if (*st) {
|
||||
*out_ptr++=WSD_PRONUNCIATION_CHAR;
|
||||
StrCpy(out_ptr,st);
|
||||
out_ptr+=StrLen(st)+1;
|
||||
}
|
||||
Free(st);
|
||||
}
|
||||
} else if (cmd==WSD_POS) {
|
||||
if(st=WSDNextEntry(&in_ptr)) {
|
||||
if (*st) {
|
||||
*out_ptr++=WSD_POS_CHAR;
|
||||
StrCpy(out_ptr,st);
|
||||
out_ptr+=StrLen(st)+1;
|
||||
}
|
||||
Free(st);
|
||||
}
|
||||
} else if (cmd==WSD_EXTRA) {
|
||||
if(st=WSDNextEntry(&in_ptr)) {
|
||||
if (*st) {
|
||||
*out_ptr++=WSD_EXTRA_CHAR;
|
||||
StrCpy(out_ptr,st);
|
||||
out_ptr+=StrLen(st)+1;
|
||||
}
|
||||
Free(st);
|
||||
}
|
||||
}
|
||||
} while (cmd==WSD_DEF||cmd==WSD_PRONUNCIATION||cmd==WSD_POS||cmd==WSD_EXTRA);
|
||||
} else
|
||||
Free(st);
|
||||
}
|
||||
}
|
||||
} while (cmd>=0);
|
||||
*out_ptr++=WSD_END_CHAR;
|
||||
*word_ptr++=WSD_END_CHAR;
|
||||
|
||||
Free(in_start);
|
||||
|
||||
"Blk Size :%d\n",WSD_BLK_SIZE;
|
||||
"Blk Cnt :%04X\n",(out_ptr-out_start+WSD_BLK_SIZE-1)/WSD_BLK_SIZE;
|
||||
"Largest Entry :%d\n",largest_entry;
|
||||
"Word Count :%d\n",word_cnt;
|
||||
|
||||
FileWrite(WSD_DEF_FILENAME,out_start,out_ptr-out_start);
|
||||
"Def File Size :%d\n",out_ptr-out_start;
|
||||
|
||||
sorted_word_start=WSDSortWords(word_start,word_ptr-word_start,word_cnt);
|
||||
FileWrite(WSD_WORD_FILENAME,sorted_word_start,word_ptr-word_start);
|
||||
"Word File Size:%d\n",word_ptr-word_start;
|
||||
|
||||
Free(out_start);
|
||||
Free(word_start);
|
||||
Free(sorted_word_start);
|
||||
}
|
||||
|
||||
WSDGen("DICTIONARY.TXT");
|
||||
@@ -0,0 +1,723 @@
|
||||
#help_index "WordStat"
|
||||
|
||||
/**** Debug code
|
||||
U0 WSPutMatrix(CWSMatrix *m)
|
||||
{
|
||||
I64 i,j;
|
||||
CWSMatrixSide *ms;
|
||||
CWS *tempw;
|
||||
|
||||
"n:%d\n",m->n;
|
||||
for (i=0;i<ws_num_matrix_words;i++) {
|
||||
ms=&m->side[i];
|
||||
"col:%d rhits:%d chits:%d\n",i,ms->row_hits,ms->col_hits;
|
||||
tempw=ms->next;
|
||||
while (tempw!=ms) {
|
||||
"substructs:%d entries:%d\n",tempw->substructs,tempw->entries;
|
||||
for (j=0;j<tempw->substructs;j++) {
|
||||
"(%04X %04X) ",
|
||||
tempw->subs[j].hits,
|
||||
tempw->subs[j].repeats;
|
||||
}
|
||||
NewLine;
|
||||
tempw=tempw->next;
|
||||
}
|
||||
}
|
||||
|
||||
View;
|
||||
}
|
||||
****/
|
||||
|
||||
CHashWS *WSHashAdd(U8 *w)
|
||||
{
|
||||
CHashWS *tempw=HashFind(w,ws_hash_table,HTT_WORD);
|
||||
if (tempw) {
|
||||
tempw->hits++;
|
||||
return tempw;
|
||||
}
|
||||
tempw=ACAlloc(sizeof(CHashWS));
|
||||
tempw->str=AStrNew(w);
|
||||
tempw->type=HTT_WORD;
|
||||
tempw->use_cnt=1;
|
||||
tempw->hits=1;
|
||||
tempw->num=-1;
|
||||
HashAdd(tempw,ws_hash_table);
|
||||
ws_num_words++;
|
||||
return tempw;
|
||||
}
|
||||
|
||||
U0 WSSidesInit(CWSMatrix *m)
|
||||
{
|
||||
I64 i;
|
||||
CWS *tempa;
|
||||
m->n=0;
|
||||
for (i=0;i<WS_MAX_MATRIX_WORDS;i++) {
|
||||
m->side[i].next=m->side[i].last=&m->side[i].next;
|
||||
m->side[i].const_minus_one=-1;
|
||||
m->side[i].row_hits=0;
|
||||
m->side[i].col_hits=0;
|
||||
tempa=AMAlloc(sizeof(CWS));
|
||||
ws_structs_size+=MSize2(tempa);
|
||||
tempa->subs[0].hits=0;
|
||||
tempa->subs[0].repeats=ws_num_matrix_words;
|
||||
tempa->entries=ws_num_matrix_words;
|
||||
tempa->substructs=1;
|
||||
QueIns(tempa,m->side[i].last);
|
||||
}
|
||||
}
|
||||
|
||||
CWS *WSStructFind(CWSMatrix *m,I64 col,I64 row,
|
||||
I64 *_row_base,I64 *_substruct)
|
||||
{
|
||||
CWS *tempa;
|
||||
I64 row_base,i,j;
|
||||
|
||||
if (row>=ws_num_matrix_words ||
|
||||
col>=ws_num_matrix_words)
|
||||
return NULL;
|
||||
if (row<ws_num_matrix_words>>1) {
|
||||
tempa=m->side[col].next;
|
||||
row_base=0;
|
||||
j=row;
|
||||
while (row>=(i=tempa->entries)) {
|
||||
row-=i;
|
||||
tempa=tempa->next;
|
||||
}
|
||||
row_base+=j-row;
|
||||
for (*_substruct=0;row>=tempa->subs[*_substruct].repeats;*_substruct=*_substruct+1) {
|
||||
row-=tempa->subs[*_substruct].repeats;
|
||||
row_base+=tempa->subs[*_substruct].repeats;
|
||||
}
|
||||
} else {
|
||||
row=ws_num_matrix_words-row;
|
||||
tempa=m->side[col].last;
|
||||
row_base=ws_num_matrix_words;
|
||||
j=row;
|
||||
while (row>(i=tempa->entries)) {
|
||||
row-=i;
|
||||
tempa=tempa->last;
|
||||
}
|
||||
row_base+=j-row;
|
||||
for (*_substruct=tempa->substructs-1;row>tempa->subs[*_substruct].repeats;
|
||||
*_substruct=*_substruct-1) {
|
||||
row-=tempa->subs[*_substruct].repeats;
|
||||
row_base-=tempa->subs[*_substruct].repeats;
|
||||
}
|
||||
row_base-=tempa->subs[*_substruct].repeats;
|
||||
}
|
||||
*_row_base=row_base;
|
||||
return tempa;
|
||||
}
|
||||
|
||||
public I64 WSGetHits(CWSMatrix *m,I64 col,I64 row)
|
||||
{
|
||||
I64 row_base,substruct;
|
||||
CWS *tempa;
|
||||
if (row>=ws_num_matrix_words ||
|
||||
col>=ws_num_matrix_words)
|
||||
return 0;
|
||||
tempa=WSStructFind(m,col,row,
|
||||
&row_base,&substruct);
|
||||
return tempa->subs[substruct].hits;
|
||||
}
|
||||
|
||||
CWSSub *WSNext(CWSSub *s,CWS **_parent)
|
||||
{
|
||||
I64 i=(s(U8 *)-(&(*_parent)->subs)(U8 *))/sizeof(CWSSub)+1;
|
||||
if (i>=(*_parent)->substructs) {
|
||||
i=0;
|
||||
*_parent=(*_parent)->next;
|
||||
if ((*_parent)->substructs==-1)
|
||||
return NULL;
|
||||
}
|
||||
return &(*_parent)->subs[i];
|
||||
}
|
||||
|
||||
CWSSub *WSLast(CWSSub *s,CWS **_parent)
|
||||
{
|
||||
I64 i=(s(U8 *)-(&(*_parent)->subs)(U8 *))/sizeof(CWSSub)-1;
|
||||
if (i<0) {
|
||||
*_parent=(*_parent)->last;
|
||||
if ((*_parent)->substructs==-1)
|
||||
return NULL;
|
||||
i=(*_parent)->substructs-1;
|
||||
}
|
||||
return &(*_parent)->subs[i];
|
||||
}
|
||||
|
||||
U0 WSRem(CWSSub *s,CWS *parent)
|
||||
{
|
||||
I64 i=(s(U8 *)-(&parent->subs)(U8 *))/sizeof(CWSSub);
|
||||
if (i<0 || i>=WS_SUBSTRUCTS_PER_STRUCT || parent->substructs<1)
|
||||
return;
|
||||
if (parent->substructs==1) {
|
||||
QueRem(parent);
|
||||
ws_structs_size-=MSize2(parent);
|
||||
Free(parent);
|
||||
} else {
|
||||
parent->entries-=s->repeats;
|
||||
parent->substructs--;
|
||||
MemCpy(&parent->subs[i],&parent->subs[i+1],
|
||||
(parent->substructs-i)*sizeof(CWSSub));
|
||||
}
|
||||
}
|
||||
|
||||
CWSSub *WSIns(CWSSub *s,CWS **_parent,CWSSub *last)
|
||||
{
|
||||
CWS *tempa,*parent=*_parent;
|
||||
I64 j,k,i=(last(U8 *)-(&parent->subs)(U8 *))/sizeof(CWSSub)+1;
|
||||
if (i>=WS_SUBSTRUCTS_PER_STRUCT) {
|
||||
i=0;
|
||||
parent=parent->next;
|
||||
*_parent=parent;
|
||||
if (parent->substructs==-1) {
|
||||
tempa=AMAlloc(sizeof(CWS));
|
||||
ws_structs_size+=MSize2(tempa);
|
||||
QueIns(tempa,parent->last);
|
||||
parent=tempa;
|
||||
*_parent=parent;
|
||||
tempa->entries=0;
|
||||
tempa->substructs=0;
|
||||
}
|
||||
}
|
||||
if (parent->substructs==WS_SUBSTRUCTS_PER_STRUCT) {
|
||||
tempa=parent->next;
|
||||
if (tempa->substructs==-1 || tempa->substructs==WS_SUBSTRUCTS_PER_STRUCT) {
|
||||
tempa=AMAlloc(sizeof(CWS));
|
||||
ws_structs_size+=MSize2(tempa);
|
||||
tempa->entries=0;
|
||||
tempa->substructs=0;
|
||||
QueIns(tempa,parent);
|
||||
k=0;
|
||||
for (j=i;j<parent->substructs;j++) {
|
||||
MemCpy(&tempa->subs[k],&parent->subs[j],sizeof(CWSSub));
|
||||
tempa->entries+=tempa->subs[k++].repeats;
|
||||
tempa->substructs++;
|
||||
}
|
||||
parent->entries-=tempa->entries;
|
||||
parent->substructs-=tempa->substructs;
|
||||
} else {
|
||||
for (j=tempa->substructs-1;j>=0;j--)
|
||||
MemCpy(&tempa->subs[j+1],&tempa->subs[j],sizeof(CWSSub));
|
||||
MemCpy(&tempa->subs[0],
|
||||
&parent->subs[WS_SUBSTRUCTS_PER_STRUCT-1],
|
||||
sizeof(CWSSub));
|
||||
parent->entries-=tempa->subs[0].repeats;
|
||||
parent->substructs--;
|
||||
tempa->entries+=tempa->subs[0].repeats;
|
||||
tempa->substructs++;
|
||||
for (j=WS_SUBSTRUCTS_PER_STRUCT-2;j>=i;j--)
|
||||
MemCpy(&parent->subs[j+1],
|
||||
&parent->subs[j],sizeof(CWSSub));
|
||||
}
|
||||
} else {
|
||||
for (j=parent->substructs-1;j>=i;j--)
|
||||
MemCpy(&parent->subs[j+1],
|
||||
&parent->subs[j],sizeof(CWSSub));
|
||||
}
|
||||
parent->entries+=s->repeats;
|
||||
parent->substructs++;
|
||||
MemCpy(&parent->subs[i],s,sizeof(CWSSub));
|
||||
return &parent->subs[i];
|
||||
}
|
||||
|
||||
CWSSub *WSCondense(CWSSub *s,CWS **_parent)
|
||||
{
|
||||
CWSSub *temps,*temps_l,*temps_n;
|
||||
CWS *tempa_l,*tempa_n;
|
||||
if ((*_parent)->substructs==-1)
|
||||
return NULL;
|
||||
temps=s;
|
||||
tempa_l=*_parent;
|
||||
temps_l=WSLast(temps,&tempa_l);
|
||||
if (temps_l && temps_l->hits==temps->hits) {
|
||||
temps_l->repeats+=temps->repeats;
|
||||
tempa_l->entries+=temps->repeats;
|
||||
WSRem(temps,*_parent);
|
||||
*_parent=tempa_l;
|
||||
temps=temps_l;
|
||||
}
|
||||
tempa_n=*_parent;
|
||||
temps_n=WSNext(temps,&tempa_n);
|
||||
if (temps_n && temps_n->hits==temps->hits) {
|
||||
temps->repeats=temps->repeats+temps_n->repeats;
|
||||
(*_parent)->entries=(*_parent)->entries+temps_n->repeats;
|
||||
WSRem(temps_n,tempa_n);
|
||||
}
|
||||
return temps;
|
||||
}
|
||||
|
||||
I64 WSHitsInc(CWSMatrix *m,I64 col,I64 row)
|
||||
{
|
||||
I64 row_base,substruct,repeats;
|
||||
CWSSub sn,*temps,*temps1,*temps_l;
|
||||
CWS *tempa,*tempa1,*tempa_l;
|
||||
|
||||
if (row>=ws_num_matrix_words ||
|
||||
col>=ws_num_matrix_words)
|
||||
return 0;
|
||||
tempa=WSStructFind(m,col,row,&row_base,&substruct);
|
||||
temps=&tempa->subs[substruct];
|
||||
repeats=temps->repeats;
|
||||
if (repeats==1) {
|
||||
temps->hits++;
|
||||
temps=WSCondense(temps,&tempa);
|
||||
} else {
|
||||
if (row==row_base) {
|
||||
temps->repeats--;
|
||||
tempa->entries--;
|
||||
sn.hits=1;
|
||||
sn.repeats=1;
|
||||
tempa_l=tempa;
|
||||
if (!(temps_l=WSLast(&tempa->subs[substruct],&tempa_l))) {
|
||||
tempa_l=tempa->last; //header
|
||||
temps_l=&tempa_l->subs[WS_SUBSTRUCTS_PER_STRUCT-1];
|
||||
}
|
||||
temps=WSIns(&sn,&tempa_l,temps_l);
|
||||
temps=WSCondense(temps,&tempa_l);
|
||||
} else if (row==repeats-1+row_base) {
|
||||
temps->repeats--;
|
||||
tempa->entries--;
|
||||
sn.hits=1;
|
||||
sn.repeats=1;
|
||||
temps=WSIns(&sn,&tempa,temps);
|
||||
temps=WSCondense(temps,&tempa);
|
||||
} else {
|
||||
tempa->entries-=repeats;
|
||||
sn.hits=temps->hits+1;
|
||||
sn.repeats=1;
|
||||
tempa1=tempa;
|
||||
temps1=temps;
|
||||
temps=WSIns(&sn,&tempa1,temps1);
|
||||
temps1->repeats=row-row_base;
|
||||
tempa->entries+=temps1->repeats;
|
||||
sn.repeats=row_base+repeats-(row+1);
|
||||
sn.hits=temps1->hits;
|
||||
WSIns(&sn,&tempa1,temps);
|
||||
}
|
||||
}
|
||||
m->n++;
|
||||
m->side[col].col_hits++;
|
||||
m->side[row].row_hits++;
|
||||
return temps->hits;
|
||||
}
|
||||
|
||||
U0 WSSingleFileAdd(U8 *buf,I64 pass)
|
||||
{
|
||||
I64 ch;
|
||||
U8 *ptr=buf,*ptr2,*ptr3;
|
||||
CHashWS *cur_ptr,*last_ptr=NULL;
|
||||
while (TRUE) {
|
||||
while (TRUE) {
|
||||
if (ch=*ptr++) {
|
||||
if (Bt(chars_bitmap_alpha_numeric,ch))
|
||||
break;
|
||||
} else
|
||||
return;
|
||||
}
|
||||
ptr3=ptr;
|
||||
ptr2=ptr;
|
||||
ptr--;
|
||||
while (TRUE) {
|
||||
if (ch=*ptr2++) {
|
||||
if (Bt(chars_bitmap_alpha_numeric,ch))
|
||||
*ptr3++=ch;
|
||||
else if (ch!=CH_CURSOR)
|
||||
break;
|
||||
} else {
|
||||
ptr2--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*ptr3=0;
|
||||
if (pass==1)
|
||||
WSHashAdd(ptr);
|
||||
else {
|
||||
cur_ptr=HashFind(ptr,ws_hash_table,HTT_WORD);
|
||||
if (cur_ptr->num<0)
|
||||
cur_ptr=NULL;
|
||||
else
|
||||
if (last_ptr)
|
||||
WSHitsInc(ws_matrix,last_ptr->num,cur_ptr->num);
|
||||
last_ptr=cur_ptr;
|
||||
}
|
||||
ptr=ptr2;
|
||||
}
|
||||
}
|
||||
|
||||
I64 WSCompare(CHashWS *e1,CHashWS *e2)
|
||||
{
|
||||
I64 r;
|
||||
if (!(r=e2->hits - e1->hits))
|
||||
r=StrCmp(e1->str,e2->str);
|
||||
return r;
|
||||
}
|
||||
|
||||
I64 WSSkipCrap(U8 *src,I64 len)
|
||||
{
|
||||
I64 j;
|
||||
j=len-1;
|
||||
while (j>=0) {
|
||||
if (Bt(chars_bitmap_alpha_numeric,src[j]))
|
||||
break;
|
||||
else
|
||||
j--;
|
||||
}
|
||||
return j+1;
|
||||
}
|
||||
|
||||
I64 WSPriorWordInStr(U8 *src,U8 *dst,I64 len,I64 buf_size)
|
||||
{
|
||||
I64 i,j=0,k;
|
||||
Bool cont=TRUE;
|
||||
i=len-1;
|
||||
while (i>=0 && cont) {
|
||||
if (!Bt(chars_bitmap_alpha_numeric,src[i]))
|
||||
cont=FALSE;
|
||||
else
|
||||
i--;
|
||||
}
|
||||
if (i>=-1 && len>0)
|
||||
for (k=i+1;k<len && j<buf_size-1;k++)
|
||||
dst[j++]=src[k];
|
||||
dst[j]=0;
|
||||
return i+1;
|
||||
}
|
||||
|
||||
|
||||
Bool WSPartialMatch(U8 *partial,U8 *complete)
|
||||
{
|
||||
I64 i,l=StrLen(partial);
|
||||
for (i=0;i<l;i++)
|
||||
if (partial[i]!=complete[i])
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
U0 WSFillIn(I64 n)
|
||||
{
|
||||
U8 *s;
|
||||
I64 len;
|
||||
if (0<=--n<ws_num_fillins) {
|
||||
s=ws_sorted_words[ws_fillin_matches[n]]->str;
|
||||
len=StrLen(s);
|
||||
if (len>ws_partial_len)
|
||||
Auto(s+ws_partial_len);
|
||||
}
|
||||
}
|
||||
|
||||
U0 WSMan(I64 n,CTask *parent_task=NULL)
|
||||
{
|
||||
U8 *buf;
|
||||
CHashWS *tempw;
|
||||
CHashSrcSym *temph;
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
if (0<=--n<ws_num_fillins && (tempw=ws_sorted_words[ws_fillin_matches[n]]) &&
|
||||
(temph=HashFind(tempw->str,Fs->hash_table,HTG_SRC_SYM)) &&
|
||||
temph->src_link) {
|
||||
buf=MPrint("Ed(\"%s\");",temph->src_link);
|
||||
Preempt(old_preempt);
|
||||
PopUp(buf,parent_task);
|
||||
Free(buf);
|
||||
}
|
||||
Preempt(old_preempt);
|
||||
}
|
||||
|
||||
U0 WSFillInAdd(I64 i,I64 j,I64 old_num_fillins)
|
||||
{
|
||||
Bool cont;
|
||||
I64 k;
|
||||
if (ws_num_fillins<WS_MAX_FILLINS || i>ws_fillin_scores[ws_num_fillins-1] ||
|
||||
i==ws_fillin_scores[ws_num_fillins-1] && ws_sorted_words[j]->hits>ws_fillin_hits[ws_num_fillins-1]) {
|
||||
cont=TRUE;
|
||||
for (k=ws_num_fillins-1;k>=old_num_fillins && cont;k--)
|
||||
if (i<=ws_fillin_scores[k] || i==ws_fillin_scores[k] && ws_sorted_words[j]->hits<=ws_fillin_hits[k]) {
|
||||
cont=FALSE;
|
||||
k++; //offset k--
|
||||
} else {
|
||||
ws_fillin_scores[k+1]=ws_fillin_scores[k];
|
||||
ws_fillin_matches[k+1]=ws_fillin_matches[k];
|
||||
ws_fillin_hits[k+1]=ws_fillin_hits[k];
|
||||
}
|
||||
if (ws_num_fillins<WS_MAX_FILLINS)
|
||||
ws_num_fillins++;
|
||||
ws_fillin_scores[k+1]=i;
|
||||
ws_fillin_hits[k+1]=ws_sorted_words[j]->hits;
|
||||
ws_fillin_matches[k+1]=j;
|
||||
}
|
||||
}
|
||||
|
||||
U0 WSPutChoices(CDoc *focus_l,CDocEntry *doc_e,CTask *focus_task)
|
||||
{
|
||||
I64 i,j,k,data_col;
|
||||
U8 ch=0,*buf,*buf1,*src=NULL,*st;
|
||||
CHashWS *w2;
|
||||
F64 timeout_time=tS+0.5;
|
||||
CHashSrcSym *temph;
|
||||
CDoc *doc=DocPut;
|
||||
|
||||
src=DocScanLine(focus_l,doc_e,&data_col);
|
||||
DocUnlock(focus_l);
|
||||
i=StrLen(src);
|
||||
buf =MAlloc(MaxI64(i+1,256));
|
||||
buf1=MAlloc(MaxI64(i+1,256));
|
||||
if (data_col==-1)
|
||||
data_col=0;
|
||||
data_col=WSPriorWordInStr(src,buf,data_col,256);
|
||||
ws_partial_len=StrLen(buf);
|
||||
data_col=WSSkipCrap(src,data_col);
|
||||
data_col=WSPriorWordInStr(src,buf1,data_col,256);
|
||||
|
||||
if (ws_cur_word && !StrCmp(ws_cur_word,buf))
|
||||
goto pc_done;
|
||||
|
||||
st=ws_cur_word;
|
||||
ws_cur_word=AStrNew(buf);
|
||||
Free(st);
|
||||
Preempt(ON);
|
||||
if (StrLen(buf1)&&ws_hash_table)
|
||||
w2=HashFind(buf1,ws_hash_table,HTT_WORD);
|
||||
else
|
||||
w2=NULL;
|
||||
ws_num_fillins=0;
|
||||
if (w2 && w2->num<ws_num_matrix_words)
|
||||
for (j=0;j<ws_num_matrix_words && tS<timeout_time;j++)
|
||||
if (WSPartialMatch(ws_cur_word,ws_sorted_words[j]->str)) {
|
||||
i=WSGetHits(ws_matrix,w2->num,ws_sorted_words[j]->num);
|
||||
WSFillInAdd(i,j,0);
|
||||
}
|
||||
k=ws_num_fillins;
|
||||
for (j=0;j<ws_num_words && tS<timeout_time;j++)
|
||||
if (WSPartialMatch(ws_cur_word,ws_sorted_words[j]->str))
|
||||
WSFillInAdd(0,j,k);
|
||||
Preempt(OFF);
|
||||
|
||||
pc_done:
|
||||
DocRst(doc,TRUE);
|
||||
doc->flags|=DOCF_MIN_SIZE;
|
||||
DocCursor;
|
||||
Fs->text_attr=LTBLUE<<4+WHITE;
|
||||
Fs->border_src =BDS_CONST;
|
||||
Fs->border_attr=LTBLUE<<4+BLACK;
|
||||
DocPrint(doc,"Word:%s\n",ws_cur_word);
|
||||
for (i=0;i<ws_num_fillins;i++) {
|
||||
st=ws_sorted_words[ws_fillin_matches[i]]->str;
|
||||
ch=CH_SPACE;
|
||||
DocPrint(doc,"F%02d ",i+1);
|
||||
if (TaskValidate(focus_task) &&
|
||||
(temph=HashFind(st,focus_task->hash_table,HTG_SRC_SYM)) &&
|
||||
temph->src_link) {
|
||||
if (temph->type&HTF_PUBLIC)
|
||||
DocPrint(doc,"$$RED$$");
|
||||
DocPrint(doc,"$$TX+UL+L+PU,\"%Q\",A=\"%s\"$$$$FG$$\n",st,temph->src_link);
|
||||
} else
|
||||
DocPrint(doc,"%s\n",st);
|
||||
}
|
||||
if (wsd_has_words)
|
||||
WSDDictWordsAdd(doc);
|
||||
|
||||
DocRecalc(doc);
|
||||
if (!LBts(&Fs->display_flags,DISPLAYf_SHOW))
|
||||
WinZBufUpdate;
|
||||
|
||||
Free(src);
|
||||
Free(buf);
|
||||
Free(buf1);
|
||||
}
|
||||
|
||||
U0 WSTask(I64)
|
||||
{
|
||||
CTask *focus_task,*original_focus_task;
|
||||
CDoc *doc;
|
||||
CDocEntry *doc_e;
|
||||
I64 ch;
|
||||
DocTermNew;
|
||||
SetWinHorz(51,Fs->win_right);
|
||||
LBts(&Fs->display_flags,DISPLAYf_WIN_ON_TOP);
|
||||
Fs->win_inhibit=WIG_TASK_DFT-WIF_BORDER-WIF_IP_L-WIF_IP_R-WIG_DBL_CLICK;
|
||||
while (TRUE) {
|
||||
if (Bt(&ws_flags,WSf_ENABLE)) {
|
||||
original_focus_task=focus_task=sys_focus_task;
|
||||
while (TaskValidate(focus_task) && Bt(&focus_task->task_flags,TASKf_INPUT_FILTER_TASK))
|
||||
focus_task=focus_task->parent_task;
|
||||
if (TaskValidate(focus_task) && (doc=DocPut(focus_task)) &&
|
||||
focus_task!=Fs && Bt(&focus_task->display_flags,DISPLAYf_SHOW)) {
|
||||
DocLock(doc);
|
||||
if (TaskValidate(focus_task) && original_focus_task==sys_focus_task &&
|
||||
doc && doc==DocPut(focus_task) && (doc_e=doc->cur_entry)) {
|
||||
if (doc_e==doc) doc_e=doc_e->last;
|
||||
while (doc_e->last!=doc && (doc_e->type_u8==DOCT_NEW_LINE ||
|
||||
doc_e->type_u8==DOCT_SOFT_NEW_LINE))
|
||||
doc_e=doc_e->last;
|
||||
while (doc_e->last->type_u8 !=DOCT_NEW_LINE && doc_e->last!=doc)
|
||||
doc_e=doc_e->last;
|
||||
if (Bt(&ws_flags,WSf_ENABLE))
|
||||
WSPutChoices(doc,doc_e,focus_task);
|
||||
else
|
||||
DocUnlock(doc);
|
||||
} else
|
||||
DocUnlock(doc);
|
||||
}
|
||||
}
|
||||
Sleep(333);
|
||||
if (ScanMsg(&ch,,1<<MSG_KEY_DOWN) && (ch==CH_ESC||ch==CH_SHIFT_ESC))
|
||||
break;
|
||||
doc=DocPut;
|
||||
DocLock(doc);
|
||||
if (doc->cur_entry!=doc && doc->cur_entry->flags1 & DOCEF1_LINK)
|
||||
'' CH_SPACE;
|
||||
DocUnlock(doc);
|
||||
}
|
||||
ws_task=NULL;
|
||||
}
|
||||
|
||||
U0 WSMainFileLstTraverse(U8 *files_find_mask,I64 pass)
|
||||
{
|
||||
U8 *buf;
|
||||
CDirEntry *tempde,*tempde1;
|
||||
try {
|
||||
tempde=tempde1=FilesFind(files_find_mask,FUF_RECURSE|FUF_JUST_TXT|FUF_JUST_FILES|FUF_CLUSTER_ORDER);
|
||||
while (tempde) {
|
||||
"%s\n",tempde->full_name;
|
||||
buf=FileRead(tempde->full_name);
|
||||
WSSingleFileAdd(buf,pass);
|
||||
Free(buf);
|
||||
tempde=tempde->next;
|
||||
}
|
||||
} catch
|
||||
Fs->catch_except=TRUE;
|
||||
DirLstDel(tempde1);
|
||||
}
|
||||
|
||||
U0 WSMatrixDel(CWSMatrix *m)
|
||||
{
|
||||
I64 i;
|
||||
CWS *tempw,*tempw1,*tempw2;
|
||||
if (!m) return;
|
||||
for (i=0;i<WS_MAX_MATRIX_WORDS;i++) {
|
||||
tempw1=&m->side[i];
|
||||
tempw=tempw1->next;
|
||||
while (tempw!=tempw1) {
|
||||
tempw2=tempw->next;
|
||||
Free(tempw);
|
||||
tempw=tempw2;
|
||||
}
|
||||
}
|
||||
Free(m);
|
||||
}
|
||||
|
||||
|
||||
public Bool WordStat(Bool val=OFF)
|
||||
{
|
||||
Bool old_wordstat=FALSE,
|
||||
old_preempt=Preempt(OFF);
|
||||
if (val) {
|
||||
while (Bt(&ws_flags,WSf_INIT_IN_PROGRESS))
|
||||
Sleep(10);
|
||||
if (TaskValidate(ws_task))
|
||||
old_wordstat=TRUE;
|
||||
else {
|
||||
ws_task=Spawn(&WSTask,NULL,"WordStat");
|
||||
TaskWait(ws_task);
|
||||
}
|
||||
if (!LBts(&ws_flags,WSf_ENABLE))
|
||||
WinToTop(ws_task);
|
||||
} else {
|
||||
LBtr(&ws_flags,WSf_ENABLE);
|
||||
if (TaskValidate(ws_task)) {
|
||||
old_wordstat=TRUE;
|
||||
Kill(ws_task);
|
||||
while (TaskValidate(ws_task))
|
||||
Yield;
|
||||
ws_task=NULL;
|
||||
}
|
||||
}
|
||||
Preempt(old_preempt);
|
||||
return old_wordstat;
|
||||
}
|
||||
|
||||
U0 WSProgressTask(Bool *_start_flag)
|
||||
{
|
||||
I64 start=sys_dsk_writes;
|
||||
progress1=0;
|
||||
progress1_max=(Size(WSD_DEF_FILENAME_Z,"+x+s")+BLK_SIZE-1)>>BLK_SIZE_BITS;
|
||||
StrCpy(progress1_desc,"Uncompressing Dictionary");
|
||||
start=sys_dsk_writes;
|
||||
*_start_flag=TRUE;
|
||||
while (progress1<progress1_max) {
|
||||
progress1=sys_dsk_writes-start;
|
||||
Sleep(10);
|
||||
}
|
||||
*progress1_desc=progress1=progress1_max=0;
|
||||
}
|
||||
|
||||
public U0 WSInit(U8 *mask=NULL)
|
||||
{
|
||||
I64 i,j=0;
|
||||
Bool start_flag;
|
||||
CHashWS *tempw;
|
||||
CBlkDev *bdev=Drv2BlkDev;
|
||||
|
||||
while (LBts(&ws_flags,WSf_INIT_IN_PROGRESS))
|
||||
Yield;
|
||||
WordStat;
|
||||
|
||||
if (IsDrvWritable && FileFind(WSD_DEF_FILENAME_Z) && !FileFind(WSD_DEF_FILENAME)) {
|
||||
if (bdev->type!=BDT_RAM) {
|
||||
start_flag=FALSE;
|
||||
Spawn(&WSProgressTask,&start_flag);
|
||||
while (!start_flag)
|
||||
Yield;
|
||||
}
|
||||
Move(WSD_DEF_FILENAME_Z,WSD_DEF_FILENAME);
|
||||
}
|
||||
|
||||
HashTableDel(ws_hash_table);
|
||||
ws_hash_table=HashTableNew(0x4000,adam_task);
|
||||
|
||||
ws_num_words=0;
|
||||
ws_num_matrix_words=0;
|
||||
ws_structs_size=0;
|
||||
Free(ws_cur_word);
|
||||
ws_cur_word=NULL;
|
||||
|
||||
"\n\nPass #1\n";
|
||||
if (mask) WSMainFileLstTraverse(mask,1);
|
||||
Free(ws_sorted_words);
|
||||
ws_sorted_words=AMAlloc(sizeof(U8 *)*ws_num_words);
|
||||
|
||||
tempw=ws_hash_table->next_added;
|
||||
while (tempw!=ws_hash_table) {
|
||||
ws_sorted_words[j++]=tempw;
|
||||
tempw=tempw->next_added;
|
||||
}
|
||||
QSortI64(ws_sorted_words,ws_num_words,&WSCompare);
|
||||
for (i=0;i<ws_num_words;i++)
|
||||
ws_sorted_words[i]->num=i;
|
||||
if (ws_num_words<=WS_MAX_MATRIX_WORDS)
|
||||
ws_num_matrix_words=ws_num_words;
|
||||
else
|
||||
ws_num_matrix_words=WS_MAX_MATRIX_WORDS;
|
||||
|
||||
WSMatrixDel(ws_matrix);
|
||||
ws_matrix=AMAlloc(sizeof(CWSMatrix));
|
||||
WSSidesInit(ws_matrix);
|
||||
|
||||
"\n\nPass #2\n";
|
||||
if (mask) WSMainFileLstTraverse(mask,2);
|
||||
|
||||
WSDWordsLoad;
|
||||
LBtr(&ws_flags,WSf_INIT_IN_PROGRESS);
|
||||
WordStat(ON);
|
||||
}
|
||||
|
||||
I64 WordStatSize()
|
||||
{
|
||||
if (ws_hash_table)
|
||||
return HashTableSize2(ws_hash_table)+ws_structs_size+
|
||||
MSize2(ws_sorted_words)+MSize2(ws_matrix)+MSize2(ws_dict_word_lst);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
#help_index ""
|
||||
Binary file not shown.
@@ -0,0 +1,97 @@
|
||||
#help_index "WordStat"
|
||||
#help_file "::/Doc/WordStat"
|
||||
|
||||
//See $LK,"::/Doc/WordStat.TXT"$
|
||||
|
||||
class CWSSub
|
||||
{
|
||||
I32 hits,repeats;
|
||||
};
|
||||
|
||||
#define WS_SUBSTRUCTS_PER_STRUCT 8
|
||||
class CWS
|
||||
{
|
||||
CWS *next,*last;
|
||||
I64 substructs, //-1 means CWSMatrixSide
|
||||
entries;
|
||||
CWSSub subs[WS_SUBSTRUCTS_PER_STRUCT];
|
||||
};
|
||||
|
||||
class CWSMatrixSide
|
||||
{
|
||||
CWS *next,*last;
|
||||
I64 const_minus_one, //-1 used to header in que
|
||||
row_hits,col_hits;
|
||||
};
|
||||
|
||||
#define WS_MAX_MATRIX_WORDS 0x8000
|
||||
class CWSMatrix
|
||||
{
|
||||
I64 n;
|
||||
CWSMatrixSide side[WS_MAX_MATRIX_WORDS];
|
||||
};
|
||||
|
||||
public I64 ws_num_words,ws_num_matrix_words;
|
||||
CHashTable *ws_hash_table=NULL;
|
||||
public U8 *ws_cur_word=NULL;
|
||||
|
||||
#define WSf_ENABLE 0
|
||||
#define WSf_INIT_IN_PROGRESS 1
|
||||
I64 ws_flags=0;
|
||||
|
||||
public CWSMatrix *ws_matrix=NULL;
|
||||
public CHashWS **ws_sorted_words=NULL;
|
||||
CTask *ws_task=NULL;
|
||||
|
||||
|
||||
#define WS_MAX_FILLINS 10
|
||||
I64 ws_partial_len=0,ws_fillin_matches[WS_MAX_FILLINS+1];
|
||||
I64 ws_num_fillins=0,ws_fillin_scores[WS_MAX_FILLINS+1],ws_fillin_hits[WS_MAX_FILLINS+1];
|
||||
|
||||
//**** Dictionary Stuff
|
||||
#help_index "WordStat/Dictionary"
|
||||
|
||||
#define WSD_WORD_FILENAME "/Adam/WordStat/WSWords.DAT.Z"
|
||||
#define WSD_DEF_FILENAME "/Adam/WordStat/WSDefs.DAT"
|
||||
#define WSD_DEF_FILENAME_Z "/Adam/WordStat/WSDefs.DAT.Z"
|
||||
|
||||
Bool wsd_has_words=FileFind(WSD_WORD_FILENAME),
|
||||
wsd_has_defs =FileFind(WSD_DEF_FILENAME)||FileFind(WSD_DEF_FILENAME_Z);
|
||||
|
||||
|
||||
#define WSD_H1 0
|
||||
#define WSD_H1_END 1
|
||||
#define WSD_DEF 2
|
||||
#define WSD_DEF_END 3
|
||||
#define WSD_PRONUNCIATION 4
|
||||
#define WSD_PRONUNCIATION_END 5
|
||||
#define WSD_POS 6
|
||||
#define WSD_POS_END 7
|
||||
#define WSD_EXTRA 8
|
||||
#define WSD_EXTRA_END 9
|
||||
#define WSD_BLK_SIZE 0x4000
|
||||
|
||||
#define WSD_END_CHAR 0x00
|
||||
#define WSD_WORD_CHAR 0x01
|
||||
#define WSD_DEF_CHAR 0x02
|
||||
#define WSD_PRONUNCIATION_CHAR 0x03
|
||||
#define WSD_POS_CHAR 0x04
|
||||
#define WSD_EXTRA_CHAR 0x05
|
||||
|
||||
public U8 *ws_dict_word_lst=NULL;
|
||||
public I64 ws_dict_word_lst_size=0,
|
||||
ws_dict_num_words=0,ws_structs_size=0;
|
||||
|
||||
extern U0 WSDWordsLoad();
|
||||
extern U0 WSDDictWordsAdd(CDoc *doc,U8 *st=NULL);
|
||||
|
||||
#define WSD_MAX_FILLINS 10
|
||||
U8 *wsd_fillins[WSD_MAX_FILLINS];
|
||||
I64 wsd_num_fillins=0;
|
||||
|
||||
// ************************************
|
||||
|
||||
#include "WSMain"
|
||||
#include "WSDict"
|
||||
|
||||
#help_index ""
|
||||
Reference in new issue
Block a user