TempleOSCD_140715.ISO
This commit is contained in:
1 parent
7ef616a20e
commit
64f679eeb9
1095 files changed
+24814
-221011
No files matched your search
+44
-51
@@ -1,18 +1,18 @@
|
||||
#help_index "WordStat/Dictionary"
|
||||
|
||||
public U0 WSDWordsLoad()
|
||||
{
|
||||
{//Put words from word list into hash table.
|
||||
I64 size;
|
||||
CHashGeneric *temph;
|
||||
U8 *in_ptr,*in_start,*st2;
|
||||
U16 *d;
|
||||
ws_dict_num_words=0;
|
||||
wsd.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;
|
||||
Free(wsd.word_lst);
|
||||
wsd.word_lst=AMAlloc(size);
|
||||
MemCpy(wsd.word_lst,in_start,size);
|
||||
wsd.word_lst_size=size;
|
||||
|
||||
while (in_ptr<in_start+size) {
|
||||
if (*in_ptr==WSD_WORD_CHAR)
|
||||
@@ -29,8 +29,8 @@ public U0 WSDWordsLoad()
|
||||
d=in_ptr;
|
||||
temph->user_data0=*d;
|
||||
in_ptr+=2;
|
||||
HashAdd(temph,ws_hash_table);
|
||||
ws_dict_num_words++;
|
||||
HashAdd(temph,ws.hash_table);
|
||||
wsd.num_words++;
|
||||
} else
|
||||
in_ptr+=3;
|
||||
}
|
||||
@@ -38,14 +38,13 @@ public U0 WSDWordsLoad()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public U8 *WSDGetDef(U8 *st,I64 def_num=1)
|
||||
{
|
||||
public U8 *WSDDefGet(U8 *st,I64 def_num=1)
|
||||
{//MAlloc str holding single dict definition of word.
|
||||
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);
|
||||
temph=HashFind(st2,ws.hash_table,HTT_DICT_WORD);
|
||||
Free(st2);
|
||||
if (temph) {
|
||||
if (f=FOpen(WSD_DEF_FILENAME,"r")) {
|
||||
@@ -82,13 +81,13 @@ public U8 *WSDGetDef(U8 *st,I64 def_num=1)
|
||||
return result;
|
||||
}
|
||||
|
||||
public U8 *WSDGetWord(U8 *st)
|
||||
{
|
||||
public U8 *WSDDefsGet(U8 *st)
|
||||
{//MAlloc str with all dict definitions of word.
|
||||
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);
|
||||
temph=HashFind(st2,ws.hash_table,HTT_DICT_WORD);
|
||||
Free(st2);
|
||||
if (temph) {
|
||||
if (f=FOpen(WSD_DEF_FILENAME,"r")) {
|
||||
@@ -121,27 +120,25 @@ public U8 *WSDGetWord(U8 *st)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Fmt of word lst entry:
|
||||
/*Fmt of word lst entry:
|
||||
U8 WSD_WORD_CHAR
|
||||
U8 word[] with terminating zero
|
||||
I16 block;
|
||||
*/
|
||||
public U8 *WSDPtAtWord(U8 *st)
|
||||
{
|
||||
public U8 *WSDWordPtAt(U8 *st)
|
||||
{//Point to word in word list.
|
||||
I64 i;
|
||||
U8 *start=ws_dict_word_lst,*r=start,
|
||||
*end=ws_dict_word_lst+ws_dict_word_lst_size;
|
||||
U8 *start=wsd.word_lst,*r=start,
|
||||
*end=wsd.word_lst+wsd.word_lst_size;
|
||||
if (!st || !*st)
|
||||
return ws_dict_word_lst;
|
||||
if (ws_dict_word_lst_size) {
|
||||
return wsd.word_lst;
|
||||
if (wsd.word_lst_size) {
|
||||
while (start+3<end) {
|
||||
r=(start+end)>>1;
|
||||
while (TRUE) {
|
||||
while (*r!=WSD_WORD_CHAR && r>ws_dict_word_lst)
|
||||
while (*r!=WSD_WORD_CHAR && r>wsd.word_lst)
|
||||
r--;
|
||||
if ((r[2]==WSD_WORD_CHAR||r[1]==WSD_WORD_CHAR)&&r-3>ws_dict_word_lst)
|
||||
if ((r[2]==WSD_WORD_CHAR||r[1]==WSD_WORD_CHAR)&&r-3>wsd.word_lst)
|
||||
r--;
|
||||
else
|
||||
break;
|
||||
@@ -159,9 +156,9 @@ public U8 *WSDPtAtWord(U8 *st)
|
||||
}
|
||||
r=(start+end)>>1;
|
||||
while (TRUE) {
|
||||
while (*r!=WSD_WORD_CHAR && r>ws_dict_word_lst)
|
||||
while (*r!=WSD_WORD_CHAR && r>wsd.word_lst)
|
||||
r--;
|
||||
if ((r[2]==WSD_WORD_CHAR||r[1]==WSD_WORD_CHAR)&&r-3>ws_dict_word_lst)
|
||||
if ((r[2]==WSD_WORD_CHAR||r[1]==WSD_WORD_CHAR)&&r-3>wsd.word_lst)
|
||||
r--;
|
||||
else
|
||||
break;
|
||||
@@ -172,27 +169,26 @@ public U8 *WSDPtAtWord(U8 *st)
|
||||
if (*r==WSD_WORD_CHAR)
|
||||
return r;
|
||||
else
|
||||
return ws_dict_word_lst;
|
||||
return wsd.word_lst;
|
||||
}
|
||||
|
||||
|
||||
U0 WSDDictWordsAdd(CDoc *doc,U8 *st=NULL)
|
||||
{
|
||||
I64 i;
|
||||
U8 *ptr;
|
||||
if (!st)
|
||||
st=ws_cur_word;
|
||||
if (st && (ptr=WSDPtAtWord(st))) {
|
||||
st=ws.cur_word;
|
||||
if (st && (ptr=WSDWordPtAt(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);
|
||||
wsd.fillins[i]=ptr-1;
|
||||
DocPrint(doc,"'%d' %-23ts",i,ptr);
|
||||
ptr+=StrLen(ptr)+3;
|
||||
}
|
||||
wsd_num_fillins=i;
|
||||
wsd.num_fillins=i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,17 +196,16 @@ U0 WSDFillin(I64 n)
|
||||
{
|
||||
U8 *s;
|
||||
I64 len;
|
||||
if (0<=n<wsd_num_fillins) {
|
||||
s=wsd_fillins[n]+1;
|
||||
if (0<=n<wsd.num_fillins) {
|
||||
s=wsd.fillins[n]+1;
|
||||
len=StrLen(s);
|
||||
if (len>ws_partial_len)
|
||||
Auto(s+ws_partial_len);
|
||||
if (len>ws.partial_len)
|
||||
Auto(s+ws.partial_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public U0 WSDDisplayDefs(CDoc *doc,U8 *st,I64 num=-1)
|
||||
{
|
||||
public U0 WSDDefsPut(CDoc *doc=NULL,U8 *st,I64 num=-1)
|
||||
{//Put to doc a dictionary definition(s) of a word.
|
||||
U8 *st2,*st3;
|
||||
I64 ch,i=0;
|
||||
if (!st) return;
|
||||
@@ -218,7 +213,7 @@ public U0 WSDDisplayDefs(CDoc *doc,U8 *st,I64 num=-1)
|
||||
st++;
|
||||
DocPrint(doc,"$$WW,1$$$$RED$$%s:$$FG$$\n\n",st);
|
||||
if (num<0) {
|
||||
if (st3=WSDGetWord(st)) {
|
||||
if (st3=WSDDefsGet(st)) {
|
||||
st2=st3;
|
||||
while (ch=*st2++) {
|
||||
switch (ch) {
|
||||
@@ -243,7 +238,7 @@ public U0 WSDDisplayDefs(CDoc *doc,U8 *st,I64 num=-1)
|
||||
Free(st3);
|
||||
}
|
||||
} else {
|
||||
while (st2=WSDGetDef(st,++i)) {
|
||||
while (st2=WSDDefGet(st,++i)) {
|
||||
if (i==num)
|
||||
DocPrint(doc,"$$GREEN$$(%d)$$FG$$ %s\n",
|
||||
i,st2);
|
||||
@@ -255,15 +250,15 @@ public U0 WSDDisplayDefs(CDoc *doc,U8 *st,I64 num=-1)
|
||||
U0 WSDPopUpDef(U8 *st,I64 num=-1,CTask *parent=NULL)
|
||||
{
|
||||
U8 *buf;
|
||||
buf=MPrint("WSDDisplayDefs(DocPut,\"%s\",%d);View;",st,num);
|
||||
buf=MStrPrint("WSDDefsPut(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);
|
||||
if (0<=n<wsd.num_fillins)
|
||||
WSDPopUpDef(wsd.fillins[n],-1,parent);
|
||||
}
|
||||
|
||||
U0 WSFindMisspelled(CDoc *doc)
|
||||
@@ -272,7 +267,7 @@ U0 WSFindMisspelled(CDoc *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) {
|
||||
if (doc_e!=doc && doc_e->de_flags&DOCEF_TAG) {
|
||||
while (col<doc_e->max_col) {
|
||||
while (col<doc_e->max_col && !Bt(chars_bitmap_word,doc_e->tag[col]))
|
||||
col++;
|
||||
@@ -282,7 +277,7 @@ U0 WSFindMisspelled(CDoc *doc)
|
||||
col2++;
|
||||
ch=doc_e->tag[col2];
|
||||
doc_e->tag[col2]=0;
|
||||
if (StrICmp(&doc_e->tag[col],WSDPtAtWord(&doc_e->tag[col])+1)) {
|
||||
if (StrICmp(&doc_e->tag[col],WSDWordPtAt(&doc_e->tag[col])+1)) {
|
||||
doc_e->tag[col2]=ch;
|
||||
doc->cur_entry=doc_e;
|
||||
doc->cur_data_col=col;
|
||||
@@ -300,5 +295,3 @@ fm_done:
|
||||
if (unlock)
|
||||
DocUnlock(doc);
|
||||
}
|
||||
|
||||
#help_index ""
|
||||
@@ -8,7 +8,7 @@ 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.
|
||||
I ran $LK,"::/Misc/ToDolDoc.CPP"$ on it, first.
|
||||
|
||||
See $LK,"::/Doc/Acknowledgements.TXT"$.
|
||||
*/
|
||||
@@ -107,7 +107,6 @@ U8 *WSDSortWords(U8 *start,I64 size,I64 word_cnt)
|
||||
return out_start;
|
||||
}
|
||||
|
||||
|
||||
U0 WSDGen(U8 *raw_dict_filename)
|
||||
{
|
||||
I64 cmd,size,word_cnt=0,largest_entry=0;
|
||||
|
||||
+106
-141
@@ -1,36 +1,8 @@
|
||||
#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);
|
||||
CHashWS *tempw=HashFind(w,ws.hash_table,HTT_WORD);
|
||||
if (tempw) {
|
||||
tempw->hits++;
|
||||
return tempw;
|
||||
@@ -41,8 +13,8 @@ CHashWS *WSHashAdd(U8 *w)
|
||||
tempw->use_cnt=1;
|
||||
tempw->hits=1;
|
||||
tempw->num=-1;
|
||||
HashAdd(tempw,ws_hash_table);
|
||||
ws_num_words++;
|
||||
HashAdd(tempw,ws.hash_table);
|
||||
ws.num_words++;
|
||||
return tempw;
|
||||
}
|
||||
|
||||
@@ -57,10 +29,10 @@ U0 WSSidesInit(CWSMatrix *m)
|
||||
m->side[i].row_hits=0;
|
||||
m->side[i].col_hits=0;
|
||||
tempa=AMAlloc(sizeof(CWS));
|
||||
ws_structs_size+=MSize2(tempa);
|
||||
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->subs[0].repeats=ws.num_matrix_words;
|
||||
tempa->entries=ws.num_matrix_words;
|
||||
tempa->substructs=1;
|
||||
QueIns(tempa,m->side[i].last);
|
||||
}
|
||||
@@ -72,10 +44,10 @@ CWS *WSStructFind(CWSMatrix *m,I64 col,I64 row,
|
||||
CWS *tempa;
|
||||
I64 row_base,i,j;
|
||||
|
||||
if (row>=ws_num_matrix_words ||
|
||||
col>=ws_num_matrix_words)
|
||||
if (row>=ws.num_matrix_words ||
|
||||
col>=ws.num_matrix_words)
|
||||
return NULL;
|
||||
if (row<ws_num_matrix_words>>1) {
|
||||
if (row<ws.num_matrix_words>>1) {
|
||||
tempa=m->side[col].next;
|
||||
row_base=0;
|
||||
j=row;
|
||||
@@ -89,9 +61,9 @@ CWS *WSStructFind(CWSMatrix *m,I64 col,I64 row,
|
||||
row_base+=tempa->subs[*_substruct].repeats;
|
||||
}
|
||||
} else {
|
||||
row=ws_num_matrix_words-row;
|
||||
row=ws.num_matrix_words-row;
|
||||
tempa=m->side[col].last;
|
||||
row_base=ws_num_matrix_words;
|
||||
row_base=ws.num_matrix_words;
|
||||
j=row;
|
||||
while (row>(i=tempa->entries)) {
|
||||
row-=i;
|
||||
@@ -109,12 +81,12 @@ CWS *WSStructFind(CWSMatrix *m,I64 col,I64 row,
|
||||
return tempa;
|
||||
}
|
||||
|
||||
public I64 WSGetHits(CWSMatrix *m,I64 col,I64 row)
|
||||
{
|
||||
public I64 WSHitsGet(CWSMatrix *m,I64 col,I64 row)
|
||||
{//Look-up markov stats for word followed by word.
|
||||
I64 row_base,substruct;
|
||||
CWS *tempa;
|
||||
if (row>=ws_num_matrix_words ||
|
||||
col>=ws_num_matrix_words)
|
||||
if (row>=ws.num_matrix_words ||
|
||||
col>=ws.num_matrix_words)
|
||||
return 0;
|
||||
tempa=WSStructFind(m,col,row,
|
||||
&row_base,&substruct);
|
||||
@@ -152,7 +124,7 @@ U0 WSRem(CWSSub *s,CWS *parent)
|
||||
return;
|
||||
if (parent->substructs==1) {
|
||||
QueRem(parent);
|
||||
ws_structs_size-=MSize2(parent);
|
||||
ws.structs_size-=MSize2(parent);
|
||||
Free(parent);
|
||||
} else {
|
||||
parent->entries-=s->repeats;
|
||||
@@ -172,7 +144,7 @@ CWSSub *WSIns(CWSSub *s,CWS **_parent,CWSSub *last)
|
||||
*_parent=parent;
|
||||
if (parent->substructs==-1) {
|
||||
tempa=AMAlloc(sizeof(CWS));
|
||||
ws_structs_size+=MSize2(tempa);
|
||||
ws.structs_size+=MSize2(tempa);
|
||||
QueIns(tempa,parent->last);
|
||||
parent=tempa;
|
||||
*_parent=parent;
|
||||
@@ -184,7 +156,7 @@ CWSSub *WSIns(CWSSub *s,CWS **_parent,CWSSub *last)
|
||||
tempa=parent->next;
|
||||
if (tempa->substructs==-1 || tempa->substructs==WS_SUBSTRUCTS_PER_STRUCT) {
|
||||
tempa=AMAlloc(sizeof(CWS));
|
||||
ws_structs_size+=MSize2(tempa);
|
||||
ws.structs_size+=MSize2(tempa);
|
||||
tempa->entries=0;
|
||||
tempa->substructs=0;
|
||||
QueIns(tempa,parent);
|
||||
@@ -253,8 +225,8 @@ I64 WSHitsInc(CWSMatrix *m,I64 col,I64 row)
|
||||
CWSSub sn,*temps,*temps1,*temps_l;
|
||||
CWS *tempa,*tempa1,*tempa_l;
|
||||
|
||||
if (row>=ws_num_matrix_words ||
|
||||
col>=ws_num_matrix_words)
|
||||
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];
|
||||
@@ -333,12 +305,12 @@ U0 WSSingleFileAdd(U8 *buf,I64 pass)
|
||||
if (pass==1)
|
||||
WSHashAdd(ptr);
|
||||
else {
|
||||
cur_ptr=HashFind(ptr,ws_hash_table,HTT_WORD);
|
||||
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);
|
||||
WSHitsInc(ws.matrix,last_ptr->num,cur_ptr->num);
|
||||
last_ptr=cur_ptr;
|
||||
}
|
||||
ptr=ptr2;
|
||||
@@ -384,7 +356,6 @@ I64 WSPriorWordInStr(U8 *src,U8 *dst,I64 len,I64 buf_size)
|
||||
return i+1;
|
||||
}
|
||||
|
||||
|
||||
Bool WSPartialMatch(U8 *partial,U8 *complete)
|
||||
{
|
||||
I64 i,l=StrLen(partial);
|
||||
@@ -398,27 +369,24 @@ U0 WSFillIn(I64 n)
|
||||
{
|
||||
U8 *s;
|
||||
I64 len;
|
||||
if (0<=--n<ws_num_fillins) {
|
||||
s=ws_sorted_words[ws_fillin_matches[n]]->str;
|
||||
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);
|
||||
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]]) &&
|
||||
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);
|
||||
PopUpEd(temph->src_link,parent_task);
|
||||
}
|
||||
Preempt(old_preempt);
|
||||
}
|
||||
@@ -427,23 +395,23 @@ 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]) {
|
||||
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]) {
|
||||
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];
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,31 +432,31 @@ U0 WSPutChoices(CDoc *focus_l,CDocEntry *doc_e,CTask *focus_task)
|
||||
if (data_col==-1)
|
||||
data_col=0;
|
||||
data_col=WSPriorWordInStr(src,buf,data_col,256);
|
||||
ws_partial_len=StrLen(buf);
|
||||
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))
|
||||
if (ws.cur_word && !StrCmp(ws.cur_word,buf))
|
||||
goto pc_done;
|
||||
|
||||
st=ws_cur_word;
|
||||
ws_cur_word=AStrNew(buf);
|
||||
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);
|
||||
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);
|
||||
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=WSHitsGet(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))
|
||||
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);
|
||||
|
||||
@@ -499,9 +467,9 @@ pc_done:
|
||||
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;
|
||||
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) &&
|
||||
@@ -513,7 +481,7 @@ pc_done:
|
||||
} else
|
||||
DocPrint(doc,"%s\n",st);
|
||||
}
|
||||
if (wsd_has_words)
|
||||
if (wsd.has_words)
|
||||
WSDDictWordsAdd(doc);
|
||||
|
||||
DocRecalc(doc);
|
||||
@@ -534,9 +502,9 @@ U0 WSTask(I64)
|
||||
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;
|
||||
Fs->win_inhibit=WIG_TASK_DFT-WIF_SELF_BORDER-WIF_SELF_IP_L-WIF_SELF_IP_R-WIG_DBL_CLICK;
|
||||
while (TRUE) {
|
||||
if (Bt(&ws_flags,WSf_ENABLE)) {
|
||||
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;
|
||||
@@ -551,7 +519,7 @@ U0 WSTask(I64)
|
||||
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))
|
||||
if (Bt(&ws.flags,WSf_ENABLE))
|
||||
WSPutChoices(doc,doc_e,focus_task);
|
||||
else
|
||||
DocUnlock(doc);
|
||||
@@ -564,11 +532,11 @@ U0 WSTask(I64)
|
||||
break;
|
||||
doc=DocPut;
|
||||
DocLock(doc);
|
||||
if (doc->cur_entry!=doc && doc->cur_entry->flags1 & DOCEF1_LINK)
|
||||
if (doc->cur_entry!=doc && doc->cur_entry->de_flags & DOCEF_LINK)
|
||||
'' CH_SPACE;
|
||||
DocUnlock(doc);
|
||||
}
|
||||
ws_task=NULL;
|
||||
ws.task=NULL;
|
||||
}
|
||||
|
||||
U0 WSMainFileLstTraverse(U8 *files_find_mask,I64 pass)
|
||||
@@ -586,7 +554,7 @@ U0 WSMainFileLstTraverse(U8 *files_find_mask,I64 pass)
|
||||
}
|
||||
} catch
|
||||
Fs->catch_except=TRUE;
|
||||
DirLstDel(tempde1);
|
||||
DirTreeDel(tempde1);
|
||||
}
|
||||
|
||||
U0 WSMatrixDel(CWSMatrix *m)
|
||||
@@ -606,30 +574,29 @@ U0 WSMatrixDel(CWSMatrix *m)
|
||||
Free(m);
|
||||
}
|
||||
|
||||
|
||||
public Bool WordStat(Bool val=OFF)
|
||||
{
|
||||
{//Turn WordStat OFF (or ON).
|
||||
Bool old_wordstat=FALSE,
|
||||
old_preempt=Preempt(OFF);
|
||||
if (val) {
|
||||
while (Bt(&ws_flags,WSf_INIT_IN_PROGRESS))
|
||||
while (Bt(&ws.flags,WSf_INIT_IN_PROGRESS))
|
||||
Sleep(10);
|
||||
if (TaskValidate(ws_task))
|
||||
if (TaskValidate(ws.task))
|
||||
old_wordstat=TRUE;
|
||||
else {
|
||||
ws_task=Spawn(&WSTask,NULL,"WordStat");
|
||||
TaskWait(ws_task);
|
||||
ws.task=Spawn(&WSTask,NULL,"WordStat");
|
||||
TaskWait(ws.task);
|
||||
}
|
||||
if (!LBts(&ws_flags,WSf_ENABLE))
|
||||
WinToTop(ws_task);
|
||||
if (!LBts(&ws.flags,WSf_ENABLE))
|
||||
WinToTop(ws.task);
|
||||
} else {
|
||||
LBtr(&ws_flags,WSf_ENABLE);
|
||||
if (TaskValidate(ws_task)) {
|
||||
LBtr(&ws.flags,WSf_ENABLE);
|
||||
if (TaskValidate(ws.task)) {
|
||||
old_wordstat=TRUE;
|
||||
Kill(ws_task);
|
||||
while (TaskValidate(ws_task))
|
||||
Kill(ws.task);
|
||||
while (TaskValidate(ws.task))
|
||||
Yield;
|
||||
ws_task=NULL;
|
||||
ws.task=NULL;
|
||||
}
|
||||
}
|
||||
Preempt(old_preempt);
|
||||
@@ -638,27 +605,27 @@ public Bool WordStat(Bool val=OFF)
|
||||
|
||||
U0 WSProgressTask(Bool *_start_flag)
|
||||
{
|
||||
I64 start=sys_dsk_writes;
|
||||
I64 start=dsk.write_cnt;
|
||||
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=dsk.write_cnt;
|
||||
*_start_flag=TRUE;
|
||||
while (progress1<progress1_max) {
|
||||
progress1=sys_dsk_writes-start;
|
||||
progress1=dsk.write_cnt-start;
|
||||
Sleep(10);
|
||||
}
|
||||
*progress1_desc=progress1=progress1_max=0;
|
||||
}
|
||||
|
||||
public U0 WSInit(U8 *mask=NULL)
|
||||
{
|
||||
{//Read files and build WordStat statistics.
|
||||
I64 i,j=0;
|
||||
Bool start_flag;
|
||||
CHashWS *tempw;
|
||||
CBlkDev *bdev=Drv2BlkDev;
|
||||
|
||||
while (LBts(&ws_flags,WSf_INIT_IN_PROGRESS))
|
||||
while (LBts(&ws.flags,WSf_INIT_IN_PROGRESS))
|
||||
Yield;
|
||||
WordStat;
|
||||
|
||||
@@ -672,52 +639,50 @@ public U0 WSInit(U8 *mask=NULL)
|
||||
Move(WSD_DEF_FILENAME_Z,WSD_DEF_FILENAME);
|
||||
}
|
||||
|
||||
HashTableDel(ws_hash_table);
|
||||
ws_hash_table=HashTableNew(0x4000,adam_task);
|
||||
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;
|
||||
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);
|
||||
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=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;
|
||||
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;
|
||||
ws.num_matrix_words=WS_MAX_MATRIX_WORDS;
|
||||
|
||||
WSMatrixDel(ws_matrix);
|
||||
ws_matrix=AMAlloc(sizeof(CWSMatrix));
|
||||
WSSidesInit(ws_matrix);
|
||||
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);
|
||||
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);
|
||||
if (ws.hash_table)
|
||||
return HashTableSize2(ws.hash_table)+ws.structs_size+
|
||||
MSize2(ws.sorted_words)+MSize2(ws.matrix)+MSize2(wsd.word_lst);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
#help_index ""
|
||||
+32
-28
@@ -31,34 +31,38 @@ class CWSMatrix
|
||||
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
|
||||
public class CWordStatGlbls
|
||||
{
|
||||
I64 num_words,num_matrix_words;
|
||||
CHashTable *hash_table;
|
||||
U8 *cur_word;
|
||||
I64 flags;
|
||||
CWSMatrix *matrix;
|
||||
CHashWS **sorted_words;
|
||||
CTask *task;
|
||||
I64 partial_len,num_fillins,
|
||||
structs_size,
|
||||
fillin_matches [WS_MAX_FILLINS+1],
|
||||
fillin_scores [WS_MAX_FILLINS+1],
|
||||
fillin_hits [WS_MAX_FILLINS+1];
|
||||
|
||||
} ws={0,0,NULL,NULL,0,NULL,NULL,NULL,0,0,0,
|
||||
{0,0,0,0,0,0,0,0,0,0,0},
|
||||
{0,0,0,0,0,0,0,0,0,0,0},
|
||||
{0,0,0,0,0,0,0,0,0,0,0}};
|
||||
|
||||
//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
|
||||
@@ -78,20 +82,20 @@ Bool wsd_has_words=FileFind(WSD_WORD_FILENAME),
|
||||
#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;
|
||||
#define WSD_MAX_FILLINS 10
|
||||
|
||||
public class CWordStatDictGlbls
|
||||
{
|
||||
U8 *word_lst;
|
||||
I64 word_lst_size,num_words,num_fillins;
|
||||
U8 *fillins[WSD_MAX_FILLINS];
|
||||
Bool has_words,has_defs;
|
||||
} wsd={NULL,0,0,0,{0,0,0,0,0,0,0,0,0,0},FALSE,FALSE};
|
||||
wsd.has_words=FileFind(WSD_WORD_FILENAME);
|
||||
wsd.has_defs =FileFind(WSD_DEF_FILENAME)||FileFind(WSD_DEF_FILENAME_Z);
|
||||
|
||||
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