TITANIC: Implemented vocab findWord

This commit is contained in:
Paul Gilbert 2016-05-10 21:27:46 -04:00
parent 3a464e8770
commit 33ef893b04
5 changed files with 63 additions and 5 deletions

View File

@ -26,7 +26,7 @@
namespace Titanic {
STVocab::STVocab(int val): _field0(0), _field4(0), _word(nullptr),
STVocab::STVocab(int val): _vocab(nullptr), _field4(0), _word(nullptr),
_fieldC(0), _field10(0), _field18(val) {
_field14 = load("STVOCAB.TXT");
}
@ -98,10 +98,46 @@ int STVocab::load(const CString &name) {
result = 4;
break;
}
if (!skipFlag && _word) {
if (result) {
// Something wrong occurred, so delete word
delete _word;
_word = nullptr;
} else {
// Add the word to the master vocab list
addWord(_word);
}
}
}
// Close resource and return result
delete file;
return result;
}
void STVocab::addWord(TTword *word) {
// TODO
}
TTword *STVocab::findWord(const TTString &str) {
TTsynonymNode *tempNode = new TTsynonymNode();
bool flag = false;
TTword *word = _vocab;
while (!flag) {
if (_field18 != 3 || strcmp(word->c_str(), str)) {
if (word->fn1(str, tempNode, _field18))
word = word->_pNext;
else
flag = true;
} else {
flag = true;
}
}
delete tempNode;
return word;
}
} // End of namespace Titanic

View File

@ -31,7 +31,7 @@ namespace Titanic {
class STVocab {
private:
int _field0;
TTword *_vocab;
int _field4;
TTword *_word;
int _fieldC;
@ -43,6 +43,16 @@ private:
* Load the vocab data
*/
int load(const CString &name);
/**
* Adds a specified word to the vocab list
*/
void addWord(TTword *word);
/**
* Scans the vocab list for an existing word match
*/
TTword *findWord(const TTString &str);
public:
STVocab(int val);
};

View File

@ -63,7 +63,8 @@ public:
*/
TTStringStatus getStatus() const { return _status; }
operator const char *() const { return _data->_string.c_str(); }
const char *c_str() const { return _data->_string.c_str(); }
operator const char *() const { return c_str(); }
};
} // End of namespace Titanic

View File

@ -27,7 +27,7 @@
namespace Titanic {
TTword::TTword(TTString &str, int mode, int val2) : _string(str),
_wordMode(mode), _field1C(val2), _fieldC(0), _synP(nullptr),
_wordMode(mode), _field1C(val2), _pNext(nullptr), _synP(nullptr),
_field20(0), _field24(0), _field28(0) {
_status = str.getStatus() == SS_VALID ? SS_VALID : SS_5;
}
@ -92,6 +92,11 @@ bool TTword::testFileHandle(SimpleFile *file) const {
return true;
}
TTword *TTword::fn1(const TTString &str, TTsynonymNode *node, int val) {
// TODO
return nullptr;
}
/*------------------------------------------------------------------------*/
TTword1::TTword1(TTString &str, int val1, int val2, int val3) :

View File

@ -32,7 +32,6 @@ namespace Titanic {
class TTword {
protected:
TTString _string;
int _fieldC;
TTsynonymNode *_synP;
TTStringStatus _status;
int _wordMode;
@ -47,6 +46,8 @@ protected:
uint readNumber(const char *str);
bool testFileHandle(SimpleFile *file) const;
public:
TTword *_pNext;
public:
TTword(TTString &str, int mode, int val2);
@ -59,6 +60,11 @@ public:
* Load the word
*/
int load(SimpleFile *file, int mode);
TTword *fn1(const TTString &str, TTsynonymNode *node, int val);
const char *c_str() const { return _string.c_str(); }
operator const char *() const { return c_str(); }
};
class TTword1 : public TTword {