* fix warnings in mail
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38271 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
6ff66b0bc0
commit
b401b82842
@ -59,7 +59,7 @@ unsigned long update_crc(unsigned long crc_accum, const char *data_blk_ptr,
|
|||||||
|
|
||||||
FileEntry::FileEntry(void)
|
FileEntry::FileEntry(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ FileEntry::FileEntry(const char *entryString)
|
|||||||
:
|
:
|
||||||
BString(entryString)
|
BString(entryString)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ WIndex::SetTo(const char *dataPath, const char *indexPath)
|
|||||||
{
|
{
|
||||||
BFile* dataFile;
|
BFile* dataFile;
|
||||||
BFile indexFile;
|
BFile indexFile;
|
||||||
|
|
||||||
dataFile = new BFile();
|
dataFile = new BFile();
|
||||||
|
|
||||||
if (dataFile->SetTo(dataPath, B_READ_ONLY) != B_OK) {
|
if (dataFile->SetTo(dataPath, B_READ_ONLY) != B_OK) {
|
||||||
@ -84,12 +84,12 @@ WIndex::SetTo(const char *dataPath, const char *indexPath)
|
|||||||
} else {
|
} else {
|
||||||
bool buildIndex = true;
|
bool buildIndex = true;
|
||||||
SetTo(dataFile);
|
SetTo(dataFile);
|
||||||
|
|
||||||
time_t mtime;
|
time_t mtime;
|
||||||
time_t modified;
|
time_t modified;
|
||||||
|
|
||||||
dataFile->GetModificationTime(&mtime);
|
dataFile->GetModificationTime(&mtime);
|
||||||
|
|
||||||
if (indexFile.SetTo(indexPath, B_READ_ONLY) == B_OK) {
|
if (indexFile.SetTo(indexPath, B_READ_ONLY) == B_OK) {
|
||||||
attr_info info;
|
attr_info info;
|
||||||
if ((indexFile.GetAttrInfo("WINDEX:version", &info) == B_OK)) {
|
if ((indexFile.GetAttrInfo("WINDEX:version", &info) == B_OK)) {
|
||||||
@ -171,25 +171,25 @@ WIndex::UnflattenIndex(BPositionIO *io)
|
|||||||
if (fEntryList)
|
if (fEntryList)
|
||||||
free(fEntryList);
|
free(fEntryList);
|
||||||
WIndexHead head;
|
WIndexHead head;
|
||||||
|
|
||||||
io->Seek(0, SEEK_SET);
|
io->Seek(0, SEEK_SET);
|
||||||
io->Read(&head, sizeof(head));
|
io->Read(&head, sizeof(head));
|
||||||
io->Seek(head.offset, SEEK_SET);
|
io->Seek(head.offset, SEEK_SET);
|
||||||
|
|
||||||
fEntrySize = head.entrySize;
|
fEntrySize = head.entrySize;
|
||||||
fEntries = head.entries;
|
fEntries = head.entries;
|
||||||
fMaxEntries = fEntriesPerBlock;
|
fMaxEntries = fEntriesPerBlock;
|
||||||
fBlockSize = fEntriesPerBlock * fEntrySize;
|
fBlockSize = fEntriesPerBlock * fEntrySize;
|
||||||
fBlocks = fEntries / fEntriesPerBlock + 1;;
|
fBlocks = fEntries / fEntriesPerBlock + 1;;
|
||||||
fIsSorted = true;
|
fIsSorted = true;
|
||||||
|
|
||||||
int32 size = (head.entries + 1) * head.entrySize;
|
int32 size = (head.entries + 1) * head.entrySize;
|
||||||
if (!(fEntryList = (uint8 *)malloc(size)))
|
if (!(fEntryList = (uint8 *)malloc(size)))
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
if (fEntries)
|
if (fEntries)
|
||||||
io->Read(fEntryList, size);
|
io->Read(fEntryList, size);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ WIndex::FlattenIndex(BPositionIO *io)
|
|||||||
if (fEntries && !fIsSorted)
|
if (fEntries && !fIsSorted)
|
||||||
SortItems();
|
SortItems();
|
||||||
WIndexHead head;
|
WIndexHead head;
|
||||||
|
|
||||||
head.entries = fEntries;
|
head.entries = fEntries;
|
||||||
head.entrySize = fEntrySize;
|
head.entrySize = fEntrySize;
|
||||||
head.offset = sizeof(WIndexHead);
|
head.offset = sizeof(WIndexHead);
|
||||||
@ -208,7 +208,7 @@ WIndex::FlattenIndex(BPositionIO *io)
|
|||||||
io->Write(&head, sizeof(head));
|
io->Write(&head, sizeof(head));
|
||||||
if (fEntries)
|
if (fEntries)
|
||||||
io->Write(fEntryList, head.entries * head.entrySize);
|
io->Write(fEntryList, head.entries * head.entrySize);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ WIndex::Lookup(int32 key)
|
|||||||
return -1;
|
return -1;
|
||||||
if (!fIsSorted)
|
if (!fIsSorted)
|
||||||
SortItems();
|
SortItems();
|
||||||
|
|
||||||
// Binary Search
|
// Binary Search
|
||||||
int32 M, Lb, Ub;
|
int32 M, Lb, Ub;
|
||||||
Lb = 0;
|
Lb = 0;
|
||||||
@ -244,11 +244,11 @@ WIndex::AddItem(WIndexEntry *entry)
|
|||||||
{
|
{
|
||||||
if (_BlockCheck() == B_ERROR)
|
if (_BlockCheck() == B_ERROR)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
memcpy(((WIndexEntry *)(fEntryList + (fEntries * fEntrySize))), entry,
|
memcpy(((WIndexEntry *)(fEntryList + (fEntries * fEntrySize))), entry,
|
||||||
fEntrySize);
|
fEntrySize);
|
||||||
fEntries++;
|
fEntries++;
|
||||||
fIsSorted = false;
|
fIsSorted = false;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -295,7 +295,7 @@ WIndex::InitIndex(void)
|
|||||||
int32
|
int32
|
||||||
WIndex::GetKey(const char *s)
|
WIndex::GetKey(const char *s)
|
||||||
{
|
{
|
||||||
|
|
||||||
int32 key = 0;
|
int32 key = 0;
|
||||||
/*int32 x;
|
/*int32 x;
|
||||||
int32 a = 84589;
|
int32 a = 84589;
|
||||||
@ -303,16 +303,16 @@ WIndex::GetKey(const char *s)
|
|||||||
int32 m = 217728;
|
int32 m = 217728;
|
||||||
while (*s) {
|
while (*s) {
|
||||||
x = *s++ - 'a';
|
x = *s++ - 'a';
|
||||||
|
|
||||||
key ^= (a * x + b) % m;
|
key ^= (a * x + b) % m;
|
||||||
key <<= 1;
|
key <<= 1;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
key = update_crc(0, s, strlen(s));
|
key = update_crc(0, s, strlen(s));
|
||||||
|
|
||||||
if (key < 0) // No negative values!
|
if (key < 0) // No negative values!
|
||||||
key = ~key;
|
key = ~key;
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,14 +344,14 @@ WIndex::FindFirst(const char *word)
|
|||||||
{
|
{
|
||||||
if (!fEntries)
|
if (!fEntries)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int32 index;
|
int32 index;
|
||||||
char nword[256];
|
char nword[256];
|
||||||
int32 key;
|
int32 key;
|
||||||
|
|
||||||
NormalizeWord(word, nword);
|
NormalizeWord(word, nword);
|
||||||
key = GetKey(nword);
|
key = GetKey(nword);
|
||||||
|
|
||||||
if ((index = Lookup(key)) < 0)
|
if ((index = Lookup(key)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
// Find first instance of key
|
// Find first instance of key
|
||||||
@ -369,13 +369,13 @@ WIndex::GetEntry(int32 index)
|
|||||||
WIndexEntry *ientry;
|
WIndexEntry *ientry;
|
||||||
FileEntry *dentry;
|
FileEntry *dentry;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
|
|
||||||
dentry = new FileEntry();
|
dentry = new FileEntry();
|
||||||
|
|
||||||
ientry = ItemAt(index);
|
ientry = ItemAt(index);
|
||||||
|
|
||||||
int32 size;
|
int32 size;
|
||||||
|
|
||||||
fDataFile->Seek(ientry->offset, SEEK_SET);
|
fDataFile->Seek(ientry->offset, SEEK_SET);
|
||||||
buffer = dentry->LockBuffer(256);
|
buffer = dentry->LockBuffer(256);
|
||||||
fDataFile->Read(buffer, 256);
|
fDataFile->Read(buffer, 256);
|
||||||
@ -392,7 +392,7 @@ WIndex::_GetEntrySize(WIndexEntry *entry, const char *entryData)
|
|||||||
{
|
{
|
||||||
// eliminate unused parameter warning
|
// eliminate unused parameter warning
|
||||||
(void)entry;
|
(void)entry;
|
||||||
|
|
||||||
return strcspn(entryData, "\n\r");
|
return strcspn(entryData, "\n\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,7 +409,7 @@ WIndex::NormalizeWord(const char *word, char *dest)
|
|||||||
{
|
{
|
||||||
const char *src;
|
const char *src;
|
||||||
char *dst;
|
char *dst;
|
||||||
|
|
||||||
// remove dots and copy
|
// remove dots and copy
|
||||||
src = word;
|
src = word;
|
||||||
dst = dest;
|
dst = dest;
|
||||||
@ -419,54 +419,53 @@ WIndex::NormalizeWord(const char *word, char *dest)
|
|||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
*dst = 0;
|
*dst = 0;
|
||||||
|
|
||||||
// convert to lower-case
|
// convert to lower-case
|
||||||
dst = dest;
|
for (dst = dest; *dst; dst++)
|
||||||
while (*dst)
|
*dst = tolower(*dst);
|
||||||
*dst++ = tolower(*dst);
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* crc32h.c -- package to compute 32-bit CRC one byte at a time using */
|
/* crc32h.c -- package to compute 32-bit CRC one byte at a time using */
|
||||||
/* the high-bit first (Big-Endian) bit ordering convention */
|
/* the high-bit first (Big-Endian) bit ordering convention */
|
||||||
/* */
|
/* */
|
||||||
/* Synopsis: */
|
/* Synopsis: */
|
||||||
/* gen_crc_table() -- generates a 256-word table containing all CRC */
|
/* gen_crc_table() -- generates a 256-word table containing all CRC */
|
||||||
/* remainders for every possible 8-bit byte. It */
|
/* remainders for every possible 8-bit byte. It */
|
||||||
/* must be executed (once) before any CRC updates. */
|
/* must be executed (once) before any CRC updates. */
|
||||||
/* */
|
/* */
|
||||||
/* unsigned update_crc(crc_accum, data_blk_ptr, data_blk_size) */
|
/* unsigned update_crc(crc_accum, data_blk_ptr, data_blk_size) */
|
||||||
/* unsigned crc_accum; char *data_blk_ptr; int data_blk_size; */
|
/* unsigned crc_accum; char *data_blk_ptr; int data_blk_size; */
|
||||||
/* Returns the updated value of the CRC accumulator after */
|
/* Returns the updated value of the CRC accumulator after */
|
||||||
/* processing each byte in the addressed block of data. */
|
/* processing each byte in the addressed block of data. */
|
||||||
/* */
|
/* */
|
||||||
/* It is assumed that an unsigned long is at least 32 bits wide and */
|
/* It is assumed that an unsigned long is at least 32 bits wide and */
|
||||||
/* that the predefined type char occupies one 8-bit byte of storage. */
|
/* that the predefined type char occupies one 8-bit byte of storage. */
|
||||||
/* */
|
/* */
|
||||||
/* The generator polynomial used for this version of the package is */
|
/* The generator polynomial used for this version of the package is */
|
||||||
/* x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0 */
|
/* x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0 */
|
||||||
/* as specified in the Autodin/Ethernet/ADCCP protocol standards. */
|
/* as specified in the Autodin/Ethernet/ADCCP protocol standards. */
|
||||||
/* Other degree 32 polynomials may be substituted by re-defining the */
|
/* Other degree 32 polynomials may be substituted by re-defining the */
|
||||||
/* symbol POLYNOMIAL below. Lower degree polynomials must first be */
|
/* symbol POLYNOMIAL below. Lower degree polynomials must first be */
|
||||||
/* multiplied by an appropriate power of x. The representation used */
|
/* multiplied by an appropriate power of x. The representation used */
|
||||||
/* is that the coefficient of x^0 is stored in the LSB of the 32-bit */
|
/* is that the coefficient of x^0 is stored in the LSB of the 32-bit */
|
||||||
/* word and the coefficient of x^31 is stored in the most significant */
|
/* word and the coefficient of x^31 is stored in the most significant */
|
||||||
/* bit. The CRC is to be appended to the data most significant byte */
|
/* bit. The CRC is to be appended to the data most significant byte */
|
||||||
/* first. For those protocols in which bytes are transmitted MSB */
|
/* first. For those protocols in which bytes are transmitted MSB */
|
||||||
/* first and in the same order as they are encountered in the block */
|
/* first and in the same order as they are encountered in the block */
|
||||||
/* this convention results in the CRC remainder being transmitted with */
|
/* this convention results in the CRC remainder being transmitted with */
|
||||||
/* the coefficient of x^31 first and with that of x^0 last (just as */
|
/* the coefficient of x^31 first and with that of x^0 last (just as */
|
||||||
/* would be done by a hardware shift register mechanization). */
|
/* would be done by a hardware shift register mechanization). */
|
||||||
/* */
|
/* */
|
||||||
/* The table lookup technique was adapted from the algorithm described */
|
/* The table lookup technique was adapted from the algorithm described */
|
||||||
/* by Avram Perez, Byte-wise CRC Calculations, IEEE Micro 3, 40 (1983).*/
|
/* by Avram Perez, Byte-wise CRC Calculations, IEEE Micro 3, 40 (1983).*/
|
||||||
|
|
||||||
|
|
||||||
#define POLYNOMIAL 0x04c11db7L
|
#define POLYNOMIAL 0x04c11db7L
|
||||||
|
|
||||||
|
|
||||||
static unsigned long crc_table[256];
|
static unsigned long crc_table[256];
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -47,7 +47,7 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MAXMETAPH is the length of the Metaphone code.
|
MAXMETAPH is the length of the Metaphone code.
|
||||||
|
|
||||||
Four is a good compromise value for English names. For comparing words
|
Four is a good compromise value for English names. For comparing words
|
||||||
@ -55,7 +55,7 @@ enum {
|
|||||||
length for more precise matches.
|
length for more precise matches.
|
||||||
|
|
||||||
The default here is 5.
|
The default here is 5.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MAXMETAPH 6
|
#define MAXMETAPH 6
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ Words::Words(bool useMetaphone)
|
|||||||
:
|
:
|
||||||
fUseMetaphone(useMetaphone)
|
fUseMetaphone(useMetaphone)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -89,13 +89,13 @@ Words::Words(BPositionIO* thes, bool useMetaphone)
|
|||||||
WIndex(thes),
|
WIndex(thes),
|
||||||
fUseMetaphone(useMetaphone)
|
fUseMetaphone(useMetaphone)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Words::~Words(void)
|
Words::~Words(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -119,27 +119,27 @@ Words::BuildIndex(void)
|
|||||||
char *nptr, *eptr;
|
char *nptr, *eptr;
|
||||||
int64 blockOffset;
|
int64 blockOffset;
|
||||||
int32 blockSize;
|
int32 blockSize;
|
||||||
|
|
||||||
// The Word Entry
|
// The Word Entry
|
||||||
WIndexEntry entry;
|
WIndexEntry entry;
|
||||||
char entryName[256], *namePtr = entryName;
|
char entryName[256], *namePtr = entryName;
|
||||||
char suffixName[256];
|
char suffixName[256];
|
||||||
char flags[32], *flagsPtr = flags;
|
char flags[32], *flagsPtr = flags;
|
||||||
|
|
||||||
// State Info
|
// State Info
|
||||||
int32 state = FIND_WORD;
|
int32 state = FIND_WORD;
|
||||||
|
|
||||||
// Make sure we are at start of file
|
// Make sure we are at start of file
|
||||||
fDataFile->Seek(0, SEEK_SET);
|
fDataFile->Seek(0, SEEK_SET);
|
||||||
entry.offset = -1;
|
entry.offset = -1;
|
||||||
|
|
||||||
// Read blocks from thes until eof
|
// Read blocks from thes until eof
|
||||||
while (true) {
|
while (true) {
|
||||||
// Get next block
|
// Get next block
|
||||||
blockOffset = fDataFile->Position();
|
blockOffset = fDataFile->Position();
|
||||||
if ((blockSize = fDataFile->Read(buffer, 16384)) == 0)
|
if ((blockSize = fDataFile->Read(buffer, 16384)) == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// parse block
|
// parse block
|
||||||
for (nptr = buffer, eptr = buffer + blockSize; nptr < eptr; nptr++) {
|
for (nptr = buffer, eptr = buffer + blockSize; nptr < eptr; nptr++) {
|
||||||
// Looking for start of word?
|
// Looking for start of word?
|
||||||
@ -163,7 +163,7 @@ Words::BuildIndex(void)
|
|||||||
// Add base word
|
// Add base word
|
||||||
entry.key = GetKey(entryName);
|
entry.key = GetKey(entryName);
|
||||||
AddItem(&entry);
|
AddItem(&entry);
|
||||||
|
|
||||||
// Add suffixed words if any
|
// Add suffixed words if any
|
||||||
if (flagsPtr != flags) {
|
if (flagsPtr != flags) {
|
||||||
// printf("Base: %s, flags: %s\n", entryName, flags);
|
// printf("Base: %s, flags: %s\n", entryName, flags);
|
||||||
@ -185,7 +185,7 @@ Words::BuildIndex(void)
|
|||||||
if (*nptr == '/') {
|
if (*nptr == '/') {
|
||||||
*namePtr = 0; // terminate word
|
*namePtr = 0; // terminate word
|
||||||
// printf("Found word: %s\n", entryName);
|
// printf("Found word: %s\n", entryName);
|
||||||
|
|
||||||
state = GET_FLAGS;
|
state = GET_FLAGS;
|
||||||
} else {
|
} else {
|
||||||
*namePtr++ = *nptr; // copy word
|
*namePtr++ = *nptr; // copy word
|
||||||
@ -210,12 +210,12 @@ Words::GetKey(const char* s)
|
|||||||
int32 key = 0;
|
int32 key = 0;
|
||||||
int32 offset;
|
int32 offset;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
metaphone(s, Metaph, GENERATE);
|
metaphone(s, Metaph, GENERATE);
|
||||||
// Compact Metaphone from 6 bytes to 4
|
// Compact Metaphone from 6 bytes to 4
|
||||||
|
|
||||||
// printf("%s -> %s: \n", s, Metaph);
|
// printf("%s -> %s: \n", s, Metaph);
|
||||||
|
|
||||||
for (sPtr = Metaph, offset = 25; *sPtr; sPtr++, offset -= 5) {
|
for (sPtr = Metaph, offset = 25; *sPtr; sPtr++, offset -= 5) {
|
||||||
c = *sPtr - 'A';
|
c = *sPtr - 'A';
|
||||||
// printf("%d,", int16(c));
|
// printf("%d,", int16(c));
|
||||||
@ -470,13 +470,13 @@ word_match(const char* reference, const char* test)
|
|||||||
char c1, c2;
|
char c1, c2;
|
||||||
s1 = test;
|
s1 = test;
|
||||||
s2 = reference;
|
s2 = reference;
|
||||||
|
|
||||||
bool a, b;
|
bool a, b;
|
||||||
|
|
||||||
while (*s2 || *s1) {
|
while (*s2 || *s1) {
|
||||||
c1 = tolower(*s1);
|
c1 = tolower(*s1);
|
||||||
c2 = tolower(*s2);
|
c2 = tolower(*s2);
|
||||||
|
|
||||||
if (*s2 && *s1) {
|
if (*s2 && *s1) {
|
||||||
if (c1 != c2) {
|
if (c1 != c2) {
|
||||||
a = (tolower(s1[1]) == c2);
|
a = (tolower(s1[1]) == c2);
|
||||||
@ -498,7 +498,7 @@ word_match(const char* reference, const char* test)
|
|||||||
s2++;
|
s2++;
|
||||||
}
|
}
|
||||||
// Equivalent Character
|
// Equivalent Character
|
||||||
else if (vsvfn[c1] == vsvfn[c2])
|
else if (vsvfn[(unsigned)c1] == vsvfn[(unsigned)c2])
|
||||||
x++;
|
x++;
|
||||||
// Unrelated Character
|
// Unrelated Character
|
||||||
else
|
else
|
||||||
@ -513,7 +513,7 @@ word_match(const char* reference, const char* test)
|
|||||||
if (*s1)
|
if (*s1)
|
||||||
s1++;
|
s1++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,7 +522,7 @@ int32
|
|||||||
suffix_word(char* dst, const char* src, char flag)
|
suffix_word(char* dst, const char* src, char flag)
|
||||||
{
|
{
|
||||||
char* end;
|
char* end;
|
||||||
|
|
||||||
end = stpcpy(dst, src);
|
end = stpcpy(dst, src);
|
||||||
flag = toupper(flag);
|
flag = toupper(flag);
|
||||||
switch(flag) {
|
switch(flag) {
|
||||||
@ -706,46 +706,46 @@ Words::FindBestMatches(BList* matches, const char* s)
|
|||||||
{
|
{
|
||||||
int32 index;
|
int32 index;
|
||||||
// printf("*** Looking for %s: ***\n", s);
|
// printf("*** Looking for %s: ***\n", s);
|
||||||
|
|
||||||
if ((index = FindFirst(s)) >= 0) {
|
if ((index = FindFirst(s)) >= 0) {
|
||||||
BString srcWord(s);
|
BString srcWord(s);
|
||||||
FileEntry* entry;
|
FileEntry* entry;
|
||||||
WIndexEntry* indexEntry;
|
WIndexEntry* indexEntry;
|
||||||
|
|
||||||
int32 key = (ItemAt(index))->key;
|
int32 key = (ItemAt(index))->key;
|
||||||
int32 suffixLength;
|
int32 suffixLength;
|
||||||
char word[128], suffixWord[128];
|
char word[128], suffixWord[128];
|
||||||
const char *src, *testWord;
|
const char *src, *testWord;
|
||||||
const char *suffixFlags;
|
const char *suffixFlags;
|
||||||
char *dst;
|
char *dst;
|
||||||
|
|
||||||
gCmpKey = srcWord.String();
|
gCmpKey = srcWord.String();
|
||||||
|
|
||||||
uint8 hashTable[32];
|
uint8 hashTable[32];
|
||||||
uint8 hashValue, highHash, lowHash;
|
uint8 hashValue, highHash, lowHash;
|
||||||
for (int32 i = 0; i < 32; i++)
|
for (int32 i = 0; i < 32; i++)
|
||||||
hashTable[i] = 0;
|
hashTable[i] = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
indexEntry = ItemAt(index);
|
indexEntry = ItemAt(index);
|
||||||
// Hash the entry offset; we use this to make sure we don't add
|
// Hash the entry offset; we use this to make sure we don't add
|
||||||
// the same word file entry twice;
|
// the same word file entry twice;
|
||||||
// It is possible for the same entry in the words file to have
|
// It is possible for the same entry in the words file to have
|
||||||
// multiple entries in the index.
|
// multiple entries in the index.
|
||||||
|
|
||||||
hashValue = indexEntry->offset % 256;
|
hashValue = indexEntry->offset % 256;
|
||||||
highHash = hashValue >> 3;
|
highHash = hashValue >> 3;
|
||||||
lowHash = 0x01 << (hashValue & 0x07);
|
lowHash = 0x01 << (hashValue & 0x07);
|
||||||
|
|
||||||
// printf("Testing Entry: %ld: hash=%d, highHash=%d, lowHash=%d\n",
|
// printf("Testing Entry: %ld: hash=%d, highHash=%d, lowHash=%d\n",
|
||||||
// indexEntry->offset, hashValue, (uint16)highHash,
|
// indexEntry->offset, hashValue, (uint16)highHash,
|
||||||
// (uint16)lowHash);
|
// (uint16)lowHash);
|
||||||
|
|
||||||
// Has this entry offset been seen before?
|
// Has this entry offset been seen before?
|
||||||
if (!(hashTable[highHash] & lowHash)) {
|
if (!(hashTable[highHash] & lowHash)) {
|
||||||
// printf("New Entry\n");
|
// printf("New Entry\n");
|
||||||
hashTable[highHash] |= lowHash; // Mark this offset so we don't add it twice
|
hashTable[highHash] |= lowHash; // Mark this offset so we don't add it twice
|
||||||
|
|
||||||
entry = GetEntry(index);
|
entry = GetEntry(index);
|
||||||
src = entry->String();
|
src = entry->String();
|
||||||
while (*src && !isalpha(*src))
|
while (*src && !isalpha(*src))
|
||||||
@ -758,7 +758,7 @@ Words::FindBestMatches(BList* matches, const char* s)
|
|||||||
suffixFlags = src + 1;
|
suffixFlags = src + 1;
|
||||||
else
|
else
|
||||||
suffixFlags = src;
|
suffixFlags = src;
|
||||||
|
|
||||||
// printf("Base Word: %s\n", word);
|
// printf("Base Word: %s\n", word);
|
||||||
// printf("Flags: %s\n", suffixFlags);
|
// printf("Flags: %s\n", suffixFlags);
|
||||||
testWord = word; // Test the base word first
|
testWord = word; // Test the base word first
|
||||||
@ -769,12 +769,12 @@ Words::FindBestMatches(BList* matches, const char* s)
|
|||||||
// And does it look close enough to the compare key?
|
// And does it look close enough to the compare key?
|
||||||
// word_match(gCmpKey, testWord)
|
// word_match(gCmpKey, testWord)
|
||||||
// <= int32((strlen(gCmpKey)-1)/2))
|
// <= int32((strlen(gCmpKey)-1)/2))
|
||||||
&& word_match(gCmpKey, testWord)
|
&& word_match(gCmpKey, testWord)
|
||||||
<= int32(float(strlen(gCmpKey)-1)*.75)) {
|
<= int32(float(strlen(gCmpKey)-1)*.75)) {
|
||||||
// printf("Added: %s\n", testWord);
|
// printf("Added: %s\n", testWord);
|
||||||
matches->AddItem((void*)(new BString(testWord)));
|
matches->AddItem((void*)(new BString(testWord)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If suffix, transform and test
|
// If suffix, transform and test
|
||||||
if (*suffixFlags) {
|
if (*suffixFlags) {
|
||||||
// Repeat until valid suffix found or end is reached
|
// Repeat until valid suffix found or end is reached
|
||||||
@ -796,7 +796,7 @@ Words::FindBestMatches(BList* matches, const char* s)
|
|||||||
|
|
||||||
index++;
|
index++;
|
||||||
} while (key == (ItemAt(index))->key);
|
} while (key == (ItemAt(index))->key);
|
||||||
|
|
||||||
return matches->CountItems();
|
return matches->CountItems();
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user