diff options
author | George Hazan <george.hazan@gmail.com> | 2015-08-17 19:39:01 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-08-17 19:39:01 +0000 |
commit | 4a6b3a2acf91421a958b9946e15a149cac29e7b5 (patch) | |
tree | 88860b2bf9b9a85c932c7dd2c2e73445d200745c /plugins/Boltun | |
parent | d0ceb5768ff3146499a0318ffe03c867c0845592 (diff) |
warning fixes
git-svn-id: http://svn.miranda-ng.org/main/trunk@14980 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Boltun')
-rw-r--r-- | plugins/Boltun/src/Engine/Mind.cpp | 188 | ||||
-rw-r--r-- | plugins/Boltun/src/Engine/TalkEngine.cpp | 212 | ||||
-rw-r--r-- | plugins/Boltun/src/boltun.cpp | 70 | ||||
-rw-r--r-- | plugins/Boltun/src/stdafx.h | 1 |
4 files changed, 199 insertions, 272 deletions
diff --git a/plugins/Boltun/src/Engine/Mind.cpp b/plugins/Boltun/src/Engine/Mind.cpp index 5158a459e6..11e636cd81 100644 --- a/plugins/Boltun/src/Engine/Mind.cpp +++ b/plugins/Boltun/src/Engine/Mind.cpp @@ -80,8 +80,7 @@ vector<tstring> Mind::Parse(tstring s) return res;
s.resize(len);
int it = 0;
- while (it != len)
- {
+ while (it != len) {
while (it != len && _istspace(s[it]))
it++;
if (it == len)
@@ -110,19 +109,15 @@ void Mind::Load(tstring filename) bool start = true;
- try
- {
- while (file.good())
- {
+ try {
+ while (file.good()) {
getline(file, st);
if (st.empty())
break;
line++;
- if (start)
- {
- if (st[0] == 65279)
- {
+ if (start) {
+ if (st[0] == 65279) {
st.erase(0, 1);
fileTypeMark = true;
}
@@ -136,16 +131,13 @@ void Mind::Load(tstring filename) c = co = new TCHAR[count + 1];
mir_tstrcpy(c, st.c_str());
size_t pos = 0;
- while (pos < count && _istspace(*c))
- {
+ while (pos < count && _istspace(*c)) {
++pos;
++c;
}
count -= pos;
- if (count > 2)
- {
- switch (*c)
- {
+ if (count > 2) {
+ switch (*c) {
case '(':
if (c[count - 1] != ')')
abort();
@@ -160,13 +152,15 @@ void Mind::Load(tstring filename) toLowerStr(c);
{
WordsList l(c);
- if (!l.IsEmpty())
+ if (!l.IsEmpty()) {
if (l.IsQuestion())
data->qkeywords.insert(make_pair(l, s1));
else
data->keywords.insert(make_pair(l, s1));
+ }
}
break;
+
case '{':
if (c[count - 1] != '}')
abort();
@@ -188,6 +182,7 @@ void Mind::Load(tstring filename) data->specialEscapes.insert(make_pair(l, s1));
}
break;
+
case '[':
if (c[count - 1] != ']')
throw error;
@@ -202,6 +197,7 @@ void Mind::Load(tstring filename) toLowerStr(c);
data->widelyUsed.insert(make_pair(c, s1));
break;
+
case '<':
if (c[count - 1] != '>')
throw error;
@@ -213,62 +209,56 @@ void Mind::Load(tstring filename) ++c;
count -= 2;
c[count] = '\0';
- if (mir_tstrcmp(c, _T("QUESTION")) == 0)
- {
+ if (mir_tstrcmp(c, _T("QUESTION")) == 0) {
toLowerStr(c);
data->question.insert(s1);
}
- else
- if (mir_tstrcmp(c, _T("IGNORED")) == 0)
- {
- toLowerStr(c);
- data->special.insert(s1);
- }
- else
- if (mir_tstrcmp(c, _T("ESCAPE")) == 0)
- {
- data->escape.push_back(s1);
- }
- else
- if (mir_tstrcmp(c, _T("FAILURE")) == 0)
- {
- data->failure.push_back(s1);
- }
- else
- if (mir_tstrcmp(c, _T("REPEAT")) == 0)
- {
- data->repeats.push_back(s1);
- }
- else
- {
- if (mir_tstrcmp(c, _T("INITIAL")) != 0)
- throw error;
- data->initial.push_back(s1);
- }
+ else if (mir_tstrcmp(c, _T("IGNORED")) == 0) {
+ toLowerStr(c);
+ data->special.insert(s1);
+ }
+ else if (mir_tstrcmp(c, _T("ESCAPE")) == 0) {
+ data->escape.push_back(s1);
+ }
+ else if (mir_tstrcmp(c, _T("FAILURE")) == 0) {
+ data->failure.push_back(s1);
+ }
+ else if (mir_tstrcmp(c, _T("REPEAT")) == 0) {
+ data->repeats.push_back(s1);
+ }
+ else {
+ if (mir_tstrcmp(c, _T("INITIAL")) != 0)
+ throw error;
+ data->initial.push_back(s1);
+ }
break;
+
case '@':
- {
if (file.eof())
throw error;
+
getline(file, s1);
line++;
format(s1);
++c;
count -= 1;
toLowerStr(c);
- tstring sc(c);
- int count1 = (int)s1.length();
- TCHAR *c = new TCHAR[count1 + 1];
- mir_tstrcpy(c, s1.c_str());
- CharLower(c);
- s1 = c;
- delete c;
- vector<tstring> strs = Parse(s1);
- data->raliases.insert(make_pair(sc, strs));
- for (vector<tstring>::const_iterator it = strs.begin(); it != strs.end(); ++it)
- data->aliases.insert(make_pair(*it, sc));
- }
- break;
+ {
+ std::transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
+ int count1 = (int)s1.length();
+ TCHAR *c = new TCHAR[count1 + 1];
+ mir_tstrcpy(c, s1.c_str());
+ CharLower(c);
+ s1 = c;
+ delete c;
+ vector<tstring> strs = Parse(s1);
+ tstring sc(c);
+ data->raliases.insert(make_pair(sc, strs));
+ for (vector<tstring>::const_iterator it = strs.begin(); it != strs.end(); ++it)
+ data->aliases.insert(make_pair(*it, sc));
+ }
+ break;
+
default:
if (file.eof())
throw error;
@@ -279,25 +269,21 @@ void Mind::Load(tstring filename) data->study.insert(make_pair(c, s1));
}
}
- else
- if (count)
- {
- if (file.eof())
- throw error;
- getline(file, s1);
- line++;
- format(s1);
- data->study.insert(make_pair(c, s1));
- }
+ else if (count) {
+ if (file.eof())
+ throw error;
+ getline(file, s1);
+ line++;
+ format(s1);
+ data->study.insert(make_pair(c, s1));
+ }
}
if (!file.eof())
- {
throw error;
- }
+
delete co;
}
- catch (...)
- {
+ catch (...) {
throw CorruptedMind(line);
delete co;
}
@@ -315,80 +301,64 @@ void Mind::Save(tstring filename) const if (fileTypeMark)
file << TCHAR(65279);
- for (string_mmap::iterator it = data->study.begin(); it != data->study.end(); ++it)
- {
+ for (string_mmap::iterator it = data->study.begin(); it != data->study.end(); ++it) {
file << (*it).first << _T('\r') << endl;
file << (*it).second << _T('\r') << endl;
}
- for (multimap<WordsList, tstring>::iterator it = data->keywords.begin(); it != data->keywords.end(); ++it)
- {
+ for (multimap<WordsList, tstring>::iterator it = data->keywords.begin(); it != data->keywords.end(); ++it) {
file << _T(" (") << (tstring)(*it).first << _T(")") << _T('\r') << endl;
file << (*it).second << _T('\r') << endl;
}
- for (multimap<WordsList, tstring>::iterator it = data->qkeywords.begin(); it != data->qkeywords.end(); ++it)
- {
+ for (multimap<WordsList, tstring>::iterator it = data->qkeywords.begin(); it != data->qkeywords.end(); ++it) {
file << _T(" (") << (tstring)(*it).first << _T(")") << _T('\r') << endl;
file << (*it).second << _T('\r') << endl;
}
- for (multimap<WordsList, tstring>::iterator it = data->specialEscapes.begin(); it != data->specialEscapes.end(); ++it)
- {
+ for (multimap<WordsList, tstring>::iterator it = data->specialEscapes.begin(); it != data->specialEscapes.end(); ++it) {
file << _T(" {") << (tstring)(*it).first << _T("}") << _T('\r') << endl;
file << (*it).second << _T('\r') << endl;
}
- for (multimap<WordsList, tstring>::iterator it = data->qspecialEscapes.begin(); it != data->qspecialEscapes.end(); ++it)
- {
+ for (multimap<WordsList, tstring>::iterator it = data->qspecialEscapes.begin(); it != data->qspecialEscapes.end(); ++it) {
file << _T(" {") << (tstring)(*it).first << _T("}") << _T('\r') << endl;
file << (*it).second << _T('\r') << endl;
}
- for (string_mmap::iterator it = data->widelyUsed.begin(); it != data->widelyUsed.end(); ++it)
- {
+ for (string_mmap::iterator it = data->widelyUsed.begin(); it != data->widelyUsed.end(); ++it) {
file << _T(" [") << (*it).first << _T("]") << _T('\r') << endl;
file << (*it).second << _T('\r') << endl;
}
- for (set<tstring>::iterator it = data->question.begin(); it != data->question.end(); ++it)
- {
+ for (set<tstring>::iterator it = data->question.begin(); it != data->question.end(); ++it) {
file << _T(" <QUESTION>") << _T('\r') << endl;
file << (*it) << _T('\r') << endl;
}
- for (set<tstring>::iterator it = data->special.begin(); it != data->special.end(); ++it)
- {
+ for (set<tstring>::iterator it = data->special.begin(); it != data->special.end(); ++it) {
file << _T(" <IGNORED>") << _T('\r') << endl;
file << (*it) << _T('\r') << endl;
}
- for (string_vec::iterator it = data->escape.begin(); it != data->escape.end(); ++it)
- {
+ for (string_vec::iterator it = data->escape.begin(); it != data->escape.end(); ++it) {
file << _T(" <ESCAPE>") << _T('\r') << endl;
file << (*it) << _T('\r') << endl;
}
- for (string_vec::iterator it = data->initial.begin(); it != data->initial.end(); ++it)
- {
+ for (string_vec::iterator it = data->initial.begin(); it != data->initial.end(); ++it) {
file << _T(" <INITIAL>") << _T('\r') << endl;
file << (*it) << _T('\r') << endl;
}
- for (string_vec::iterator it = data->failure.begin(); it != data->failure.end(); ++it)
- {
+ for (string_vec::iterator it = data->failure.begin(); it != data->failure.end(); ++it) {
file << _T(" <FAILURE>") << _T('\r') << endl;
file << (*it) << _T('\r') << endl;
}
- for (string_vec::iterator it = data->repeats.begin(); it != data->repeats.end(); ++it)
- {
+ for (string_vec::iterator it = data->repeats.begin(); it != data->repeats.end(); ++it) {
file << _T(" <REPEAT>") << _T('\r') << endl;
file << (*it) << _T('\r') << endl;
}
- for (map<tstring, vector<tstring>>::const_iterator it = data->raliases.begin(); it != data->raliases.end(); ++it)
- {
+ for (map<tstring, vector<tstring>>::const_iterator it = data->raliases.begin(); it != data->raliases.end(); ++it) {
tstring s;
const vector<tstring>& v = (*it).second;
bool first = true;
- for (vector<tstring>::const_iterator it1 = v.begin(); it1 != v.end(); ++it1)
- {
- if (first)
- {
+ for (vector<tstring>::const_iterator it1 = v.begin(); it1 != v.end(); ++it1) {
+ if (first) {
first = false;
s = *it1;
}
- else
- {
+ else {
s += _T(" ") + *it1;
}
}
@@ -404,8 +374,7 @@ void Mind::LoadSmiles(tstring filename) data->smiles.clear();
tstring s;
unsigned int l = 0;
- while (!file.eof())
- {
+ while (!file.eof()) {
getline(file, s);
if (s.length() > l)
l = (int)s.length();
@@ -420,8 +389,7 @@ void Mind::LoadSmiles(void *smiles, size_t size) TCHAR* buf = (TCHAR*)smiles;
unsigned l = 0;
TCHAR* end = buf + size;
- while (buf != end)
- {
+ while (buf != end) {
TCHAR *lend = buf;
while (lend != end && *lend != _T('\r'))
lend++;
diff --git a/plugins/Boltun/src/Engine/TalkEngine.cpp b/plugins/Boltun/src/Engine/TalkEngine.cpp index 1c4465402b..ffee42b7c7 100644 --- a/plugins/Boltun/src/Engine/TalkEngine.cpp +++ b/plugins/Boltun/src/Engine/TalkEngine.cpp @@ -43,28 +43,23 @@ void TalkBot::UpdateStartChar(tstring& str) if (!makeLowercase)
return;
size_t l = str.length();
- if (l)
- {
+ if (l) {
//Answers starting with ' ' must remain unchanged.
- if (str[0] == _T(' '))
- {
+ if (str[0] == _T(' ')) {
str = str.substr(1);
return;
}
- for (size_t i = 0; i < l; i++)
- {
+ for (size_t i = 0; i < l; i++) {
TCHAR cl = (TCHAR)CharLower((LPTSTR)(void*)(long)str[i]);
TCHAR cu = (TCHAR)CharUpper((LPTSTR)(void*)(long)str[i]);
- if (i != l - 1)
- {
+ if (i != l - 1) {
//Do not react to BLONDE ANSWERS
TCHAR ncl = (TCHAR)CharLower((LPTSTR)(void*)(long)str[i + 1]);
TCHAR ncu = (TCHAR)CharUpper((LPTSTR)(void*)(long)str[i + 1]);
if (ncl != ncu && str[i + 1] == ncu)
break;
}
- if (cl != cu)
- {
+ if (cl != cu) {
str[i] = cl;
break;
}
@@ -99,16 +94,13 @@ tstring TalkBot::ReplaceAliases(const tstring &message) tstring result;
map<size_t, tstring> sm;
//Find smiles
- for (size_t i = 0; i < sentence.length() - 1; i++)
- {
+ for (size_t i = 0; i < sentence.length() - 1; i++) {
unsigned max = (int)(sentence.length() - i);
if (max > mind.GetData()->maxSmileLen)
max = mind.GetData()->maxSmileLen;
- for (unsigned j = max; j > 0; j--)
- {
+ for (unsigned j = max; j > 0; j--) {
tstring item = sentence.substr(i, j);
- if (mind.GetData()->smiles.find(item) != mind.GetData()->smiles.end())
- {
+ if (mind.GetData()->smiles.find(item) != mind.GetData()->smiles.end()) {
sm[i] = item;
sentence.replace(i, j, _T("\1"));
break;
@@ -118,15 +110,12 @@ tstring TalkBot::ReplaceAliases(const tstring &message) int len = (int)sentence.length();
bool hadQuestionSigns = false;
int it = 0;
- while (it != len)
- {
- while (it != len && _tcschr(dividers, sentence[it]))
- {
+ while (it != len) {
+ while (it != len && _tcschr(dividers, sentence[it])) {
if (sentence[it] == _T('?'))
hadQuestionSigns = true;
map<size_t, tstring>::iterator smit;
- if (sentence[it] == '\1')
- {
+ if (sentence[it] == '\1') {
smit = sm.find(it);
result.append((*smit).second);
}
@@ -137,8 +126,7 @@ tstring TalkBot::ReplaceAliases(const tstring &message) if (it == len)
break;
int start = it;
- while (true)
- {
+ while (true) {
while (it != len && !_tcschr(dividers, sentence[it]))
it++;
if (it == len || sentence[it] != _T('-'))
@@ -169,38 +157,37 @@ tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contact //Part 2
if (FindExact(contactData, incomingMessage, mind.GetData()->study, res)) //study
{
-#ifdef DEBUG_PREFIXES
- mm.insert(make_pair(LOOKSLIKE, _T("(study_all) ")+res));
-#else
+ #ifdef DEBUG_PREFIXES
+ mm.insert(make_pair(LOOKSLIKE, _T("(study_all) ") + res));
+ #else
mm.insert(make_pair(LOOKSLIKE, res));
-#endif
+ #endif
maxValue = LOOKSLIKE;
}
//Part 3
vector<tstring> sentences;
SplitSectences(incomingMessage, sentences);
ValueChooser<> ch(sentences, true); //Using random order of sentences.
- while ((res = ch.GetString()) != _T(""))
- {
+ while ((res = ch.GetString()) != _T("")) {
//Part 4
if (FindExact(contactData, res, mind.GetData()->widelyUsed, res)) //widelyUsed
{
-#ifdef DEBUG_PREFIXES
- mm.insert(make_pair(BEST, _T("(widelyused_sent) ")+res));
-#else
+ #ifdef DEBUG_PREFIXES
+ mm.insert(make_pair(BEST, _T("(widelyused_sent) ") + res));
+ #else
mm.insert(make_pair(BEST, res));
-#endif
+ #endif
if (maxValue > BEST)
maxValue = BEST;
}
//Part 5
if (FindExact(contactData, res, mind.GetData()->study, res)) //study
{
-#ifdef DEBUG_PREFIXES
- mm.insert(make_pair(LOOKSLIKE, _T("(study_sent) ")+res));
-#else
+ #ifdef DEBUG_PREFIXES
+ mm.insert(make_pair(LOOKSLIKE, _T("(study_sent) ") + res));
+ #else
mm.insert(make_pair(LOOKSLIKE, res));
-#endif
+ #endif
if (maxValue > LOOKSLIKE)
maxValue = LOOKSLIKE;
}
@@ -211,13 +198,12 @@ tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contact //Part 7, 8
res = _T("");
FindByKeywords(contactData, keywords, res/*, ures*/, isQuestion); //keywords
- if (res != _T(""))
- {
-#ifdef DEBUG_PREFIXES
- mm.insert(make_pair(LOOKSLIKE, _T("(keywords) ")+res));
-#else
+ if (res != _T("")) {
+ #ifdef DEBUG_PREFIXES
+ mm.insert(make_pair(LOOKSLIKE, _T("(keywords) ") + res));
+ #else
mm.insert(make_pair(LOOKSLIKE, res));
-#endif
+ #endif
if (maxValue > LOOKSLIKE)
maxValue = LOOKSLIKE;
}
@@ -231,39 +217,38 @@ tstring TalkBot::AllReplies(const tstring &incomingMessage, ContactData *contact if (maxValue > LOOKSLIKE2)
maxValue = LOOKSLIKE2;
}*/
- //Part 9
+ //Part 9
if (FindByOthers(contactData, otherwords, res, isQuestion)) //specialEscapes
{
-#ifdef DEBUG_PREFIXES
- mm.insert(make_pair(BAD, _T("(otherwords) ")+res));
-#else
+ #ifdef DEBUG_PREFIXES
+ mm.insert(make_pair(BAD, _T("(otherwords) ") + res));
+ #else
mm.insert(make_pair(BAD, res));
-#endif
+ #endif
if (maxValue > BAD)
maxValue = BAD;
}
}
- if (!beSilent)
- {
+ if (!beSilent) {
//Part 10
if (FindAny(contactData->escape, res)) //escape
{
-#ifdef DEBUG_PREFIXES
+ #ifdef DEBUG_PREFIXES
mm.insert(make_pair(FAIL, _T("(escape) ") + res));
-#else
+ #else
mm.insert(make_pair(FAIL, res));
-#endif
+ #endif
if (maxValue > FAIL)
maxValue = FAIL;
}
//Part 11
if (!understandAlways && FindAny(contactData->failure, res)) //failure
{
-#ifdef DEBUG_PREFIXES
+ #ifdef DEBUG_PREFIXES
mm.insert(make_pair(FAIL, _T("(failure) ") + res));
-#else
+ #else
mm.insert(make_pair(FAIL, res));
-#endif
+ #endif
if (maxValue > FAIL)
maxValue = FAIL;
}
@@ -280,26 +265,24 @@ TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, tstring incomingMessage, delete[] str;
ContactData *contactData = contactDatas->GetData(contact);
- if (incomingMessage == contactData->lastMessage && GetTickCount() < contactData->lastMessageTime + 30 * 60 * 1000)
- {
+ if (incomingMessage == contactData->lastMessage && GetTickCount() < contactData->lastMessageTime + 30 * 60 * 1000) {
MessageInfo *info;
//only 2-3 repeats
- if (contactData->repeatCount < 2 || contactData->repeatCount == 2 && (rand() % 2))
- {
+ if (contactData->repeatCount < 2 || contactData->repeatCount == 2 && (rand() % 2)) {
const vector<tstring>& v = mind.GetData()->repeats;
tstring res = v[rand() % v.size()];
-#ifdef DEBUG_PREFIXES
+ #ifdef DEBUG_PREFIXES
info = new MessageInfo(incomingMessage, _T("(repeat_norm) ") + res);
-#else
+ #else
info = new MessageInfo(incomingMessage, res);
-#endif
+ #endif
}
else
-#ifdef DEBUG_PREFIXES
+ #ifdef DEBUG_PREFIXES
info = new MessageInfo(incomingMessage, _T("(repeat_silence)"));
-#else
+ #else
info = new MessageInfo(incomingMessage, _T(""));
-#endif
+ #endif
if (saveChoice)
RecordAnswer(contactData, *info);
contactDatas->PutData(contact);
@@ -310,14 +293,13 @@ TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, tstring incomingMessage, Level maxValue = NOTHING;
tstring res = AllReplies(incomingMessage, contactData, maxValue, mm);
- if (!res.empty())
- {
+ if (!res.empty()) {
UpdateStartChar(res);
-#ifdef DEBUG_PREFIXES
+ #ifdef DEBUG_PREFIXES
MessageInfo *info = new MessageInfo(incomingMessage, _T("(widelyused_all) ") + res);
-#else
+ #else
MessageInfo *info = new MessageInfo(incomingMessage, res);
-#endif
+ #endif
if (saveChoice)
RecordAnswer(contactData, *info);
contactDatas->PutData(contact);
@@ -327,14 +309,13 @@ TalkBot::MessageInfo* TalkBot::Reply(MCONTACT contact, tstring incomingMessage, incomingMessage = ReplaceAliases(incomingMessage);
res = AllReplies(incomingMessage, contactData, maxValue, mm);
- if (!res.empty())
- {
+ if (!res.empty()) {
UpdateStartChar(res);
-#ifdef DEBUG_PREFIXES
+ #ifdef DEBUG_PREFIXES
MessageInfo *info = new MessageInfo(incomingMessage, _T("(widelyused_all) ") + res);
-#else
+ #else
MessageInfo *info = new MessageInfo(incomingMessage, res);
-#endif
+ #endif
if (saveChoice)
RecordAnswer(contactData, *info);
contactDatas->PutData(contact);
@@ -355,8 +336,7 @@ bool TalkBot::FindExact(ContactData *contactData, const tstring &incomingMessage const multimap<tstring, tstring>& map, tstring& res)
{
int max = (int)map.count(incomingMessage);
- if (!max)
- {
+ if (!max) {
TCHAR c = incomingMessage[incomingMessage.length() - 1];
if (c != _T('?') && c != _T('.') && c != _T('!'))
return FindExact(contactData, incomingMessage + _T('.'), map, res);
@@ -400,15 +380,12 @@ void TalkBot::SplitSectences(const tstring &incomingMessage, vector<tstring>& ve //FIXME: (THINK ABOUT IT:-))these chars not always mark the end of sentence.
const TCHAR symbols[] = _T(".?!");
int it = 0, len = (int)incomingMessage.length();
- while (it != len)
- {
+ while (it != len) {
while (it != len && _istspace(incomingMessage[it]))
it++;
int start = it;
- while (it != len)
- {
- if (_tcschr(symbols, incomingMessage[it++]))
- {
+ while (it != len) {
+ if (_tcschr(symbols, incomingMessage[it++])) {
//Test for a :-! smile
if (it > 2 && incomingMessage[it - 1] == _T('!')
&& incomingMessage[it - 2] == _T('-')
@@ -427,8 +404,7 @@ void TalkBot::SplitSectences(const tstring &incomingMessage, vector<tstring>& ve tstring LevelToStr(TalkBot::Level target)
{
tstring lev;
- switch (target)
- {
+ switch (target) {
case TalkBot::BEST: lev = _T("BEST(0)"); break;
case TalkBot::LOOKSLIKE: lev = _T("LOOKSLIKE(1)"); break;
case TalkBot::BAD: lev = _T("BAD(2)"); break;
@@ -441,12 +417,12 @@ tstring LevelToStr(TalkBot::Level target) tstring TalkBot::ChooseResult(ContactData *contactData, Level maxValue, const multimap<Level, tstring> &mm)
{
-#ifdef DEBUG_SHOW_VARIANTS
+ #ifdef DEBUG_SHOW_VARIANTS
AddBotMessage(_T(">>Availabe:"));
for (multimap<Level, tstring>::iterator it = mm.begin(); it != mm.end(); it++)
AddBotMessage(LevelToStr((*it).first) + _T(": ") + (*it).second);
AddBotMessage(_T(">>Result:"));
-#endif
+ #endif
if (maxValue == NOTHING)
return _T("");
Level target = maxValue;
@@ -454,30 +430,29 @@ tstring TalkBot::ChooseResult(ContactData *contactData, Level maxValue, const mu pair<lt_cit, lt_cit> range = mm.equal_range(target);
for (lt_cit it = range.first; it != range.second; ++it)
contactData->chooser.AddChoice((*it).second);
-#ifdef DEBUG_SHOW_LEVEL
+ #ifdef DEBUG_SHOW_LEVEL
tstring lev = LevelToStr(target);
return lev + _T(": ") + contactData->chooser.Choose();
-#else
+ #else
return contactData->chooser.Choose();
-#endif
+ #endif
}
-void TalkBot::FindByKeywords(ContactData *contactData, const vector<tstring> &keywords, tstring& res/*, tstring& ures*/,
+void TalkBot::FindByKeywords(ContactData *contactData, const vector<tstring> &keywords, tstring& res/*, tstring& ures*/,
bool isQuestion)
{
if (keywords.size() == 0)
return;
const multimap<WordsList, tstring> &keys = isQuestion ? mind.GetData()->qkeywords :
mind.GetData()->keywords;
- for (multimap<WordsList, tstring>::const_iterator it = keys.begin(); it != keys.end(); ++it)
- {
+ for (multimap<WordsList, tstring>::const_iterator it = keys.begin(); it != keys.end(); ++it) {
float prio;
if ((*it).first.MatchesAll(keywords/*, strict*/, prio))
-#ifdef DEBUG_SHOW_SOLUTION_REASON
+ #ifdef DEBUG_SHOW_SOLUTION_REASON
contactData->chooser.AddChoice((tstring)(*it).first + _T(": - ") + (*it).second, prio);
-#else
+ #else
contactData->chooser.AddChoice((*it).second, prio);
-#endif
+ #endif
}
res = contactData->chooser.Choose();
}
@@ -488,14 +463,13 @@ bool TalkBot::FindByOthers(ContactData *contactData, const vector<tstring> &othe const multimap<WordsList, tstring> &specs = isQuestion ? mind.GetData()->qspecialEscapes :
mind.GetData()->specialEscapes;
for (multimap<WordsList, tstring>::const_iterator it = specs.begin();
- it != specs.end(); ++it)
- if ((*it).first.MatchesAny(otherwords))
- {
-#ifdef DEBUG_SHOW_SOLUTION_REASON
+ it != specs.end(); ++it)
+ if ((*it).first.MatchesAny(otherwords)) {
+ #ifdef DEBUG_SHOW_SOLUTION_REASON
contactData->chooser.AddChoice((tstring)(*it).first + _T(": - ") + (*it).second);
-#else
+ #else
contactData->chooser.AddChoice((*it).second);
-#endif
+ #endif
}
res = contactData->chooser.Choose();
if (res.empty())
@@ -516,17 +490,14 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector<tstring>& keywords, vector<tstring> words;
map<size_t, tstring> sm;
//Find smiles
- for (size_t i = 0; i < sentence.length() - 1; i++)
- {
+ for (size_t i = 0; i < sentence.length() - 1; i++) {
unsigned max = (int)(sentence.length() - i);
if (max > mind.GetData()->maxSmileLen)
max = mind.GetData()->maxSmileLen;
- for (unsigned j = max; j > 0; j--)
- {
+ for (unsigned j = max; j > 0; j--) {
tstring item = sentence.substr(i, j);
if (mind.GetData()->smiles.find(item)
- != mind.GetData()->smiles.end())
- {
+ != mind.GetData()->smiles.end()) {
sm[i] = item;
sentence.replace(i, j, _T(" "));
break;
@@ -536,10 +507,8 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector<tstring>& keywords, len = (int)sentence.length();
bool hadQuestionSigns = false;
int it = 0;
- while (it != len)
- {
- while (it != len && _tcschr(dividers, sentence[it]))
- {
+ while (it != len) {
+ while (it != len && _tcschr(dividers, sentence[it])) {
if (sentence[it] == _T('?'))
hadQuestionSigns = true;
map<size_t, tstring>::iterator smit;
@@ -551,8 +520,7 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector<tstring>& keywords, break;
hadQuestionSigns = false;
int start = it;
- while (true)
- {
+ while (true) {
while (it != len && !_tcschr(dividers, sentence[it]))
it++;
if (it == len || sentence[it] != _T('-'))
@@ -566,18 +534,16 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector<tstring>& keywords, words.push_back(str);
}
isQuestion = hadQuestionSigns;
- for (vector<tstring>::iterator it = words.begin(); it != words.end(); ++it)
- {
- if (!isQuestion)
- {
+ for (vector<tstring>::iterator it = words.begin(); it != words.end(); ++it) {
+ if (!isQuestion) {
if (mind.GetData()->question.find(*it) != mind.GetData()->question.end())
isQuestion = true;
}
if (mind.GetData()->special.find(*it) != mind.GetData()->special.end())
otherwords.push_back(*it);
-#ifdef EXCLUDE_SPECIAL_WORDS
+ #ifdef EXCLUDE_SPECIAL_WORDS
else
-#endif
+ #endif
keywords.push_back(*it);
}
}
@@ -595,4 +561,4 @@ void TalkBot::SetLowercase(const bool isLowercase) void TalkBot::SetUnderstandAlways(const bool understandAlways)
{
this->understandAlways = understandAlways;
-}
\ No newline at end of file +}
diff --git a/plugins/Boltun/src/boltun.cpp b/plugins/Boltun/src/boltun.cpp index c9352c3a33..154885f92f 100644 --- a/plugins/Boltun/src/boltun.cpp +++ b/plugins/Boltun/src/boltun.cpp @@ -24,7 +24,6 @@ int hLangpack; TalkBot* bot = NULL;
-
#define MAX_WARN_TEXT 1024
#define MAX_MIND_FILE 1024
@@ -350,11 +349,12 @@ static INT_PTR CALLBACK EngineDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP UpdateUnderstandAlwaysCheckbox(hwndDlg);
loading = false;
return TRUE;
+
case WM_COMMAND:
param = LOWORD(wParam);
if (param == IDC_ENGINE_SILENT && HIWORD(wParam) == BN_CLICKED)
UpdateUnderstandAlwaysCheckbox(hwndDlg);
- OPENFILENAME ofn;
+
switch (param) {
case IDC_BTNPATH:
{
@@ -365,34 +365,28 @@ static INT_PTR CALLBACK EngineDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP if (fullname != Config.MindFileName)
delete[] fullname;
- memset(&ofn, 0, sizeof(ofn));
+ OPENFILENAME ofn = { 0 };
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = GetParent(hwndDlg);
- TCHAR* mind = TranslateTS(MIND_FILE_DESC);
- TCHAR* anyfile = TranslateTS(ALL_FILES_DESC);
- size_t l = mir_tstrlen(MIND_DIALOG_FILTER)
- + mir_tstrlen(mind) + mir_tstrlen(anyfile);
- TCHAR *filt = new TCHAR[l];
- mir_sntprintf(filt, l, MIND_DIALOG_FILTER, mind, anyfile);
- for (size_t i = 0; i < l; i++)
- if (filt[i] == '\1')
- filt[i] = '\0';
- ofn.lpstrFilter = filt;
+ TCHAR *mind = TranslateTS(MIND_FILE_DESC);
+ TCHAR *anyfile = TranslateTS(ALL_FILES_DESC);
+ CMString filt(FORMAT, MIND_DIALOG_FILTER, mind, anyfile);
+ filt.Replace('\1', '\0');
+ ofn.lpstrFilter = filt;
ofn.lpstrFile = filename;
ofn.nMaxFile = fileNameSize;
ofn.Flags = OFN_FILEMUSTEXIST;
ofn.lpstrInitialDir = tszPath;
if (!GetOpenFileName(&ofn)) {
delete[] filename;
- delete[] filt;
break;
}
- delete[] filt;
- TCHAR* origf = filename;
- TCHAR* f = filename;
- TCHAR* p = tszPath;
+
+ TCHAR *origf = filename;
+ TCHAR *f = filename;
+ TCHAR *p = tszPath;
while (*p && *f) {
TCHAR p1 = (TCHAR)CharLower((TCHAR*)(long)*p++);
TCHAR f1 = (TCHAR)CharLower((TCHAR*)(long)*f++);
@@ -405,6 +399,7 @@ static INT_PTR CALLBACK EngineDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP SetDlgItemText(hwndDlg, IDC_MINDFILE, filename);
delete[] origf;
}
+
case IDC_BTNRELOAD:
{
const TCHAR *c = Config.MindFileName;
@@ -415,8 +410,9 @@ static INT_PTR CALLBACK EngineDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP mir_sntprintf(message, _countof(message), TranslateTS(FAILED_TO_LOAD_BASE), line, c);
MessageBox(NULL, message, TranslateTS(BOLTUN_ERROR), MB_ICONERROR | MB_TASKMODAL | MB_OK);
}
- break;
}
+ break;
+
default:
if (!loading) {
if (param == IDC_MINDFILE/* && HIWORD(wParam) != EN_CHANGE*/)
@@ -425,27 +421,23 @@ static INT_PTR CALLBACK EngineDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LP }
}
break;
+
case WM_NOTIFY:
- {
- NMHDR* nmhdr = (NMHDR*)lParam;
- switch (nmhdr->code) {
- case PSN_APPLY:
- case PSN_KILLACTIVE:
- {
- Config.EngineStaySilent = IsDlgButtonChecked(hwndDlg, IDC_ENGINE_SILENT) == BST_CHECKED ? TRUE : FALSE;
- Config.EngineMakeLowerCase = IsDlgButtonChecked(hwndDlg, IDC_ENGINE_LOWERCASE) == BST_CHECKED ? TRUE : FALSE;
- Config.EngineUnderstandAlways = IsDlgButtonChecked(hwndDlg, IDC_ENGINE_UNDERSTAND_ALWAYS) == BST_CHECKED ? TRUE : FALSE;
- UpdateEngine();
- TCHAR c[MAX_MIND_FILE];
- bTranslated = GetDlgItemText(hwndDlg, IDC_MINDFILE, c, _countof(c));
- if (bTranslated)
- Config.MindFileName = c;
- else
- Config.MindFileName = DEFAULT_MIND_FILE;
- }
- return TRUE;
- }
- break;
+ NMHDR *nmhdr = (NMHDR*)lParam;
+ switch (nmhdr->code) {
+ case PSN_APPLY:
+ case PSN_KILLACTIVE:
+ Config.EngineStaySilent = IsDlgButtonChecked(hwndDlg, IDC_ENGINE_SILENT) == BST_CHECKED ? TRUE : FALSE;
+ Config.EngineMakeLowerCase = IsDlgButtonChecked(hwndDlg, IDC_ENGINE_LOWERCASE) == BST_CHECKED ? TRUE : FALSE;
+ Config.EngineUnderstandAlways = IsDlgButtonChecked(hwndDlg, IDC_ENGINE_UNDERSTAND_ALWAYS) == BST_CHECKED ? TRUE : FALSE;
+ UpdateEngine();
+ TCHAR c[MAX_MIND_FILE];
+ bTranslated = GetDlgItemText(hwndDlg, IDC_MINDFILE, c, _countof(c));
+ if (bTranslated)
+ Config.MindFileName = c;
+ else
+ Config.MindFileName = DEFAULT_MIND_FILE;
+ return TRUE;
}
break;
}
diff --git a/plugins/Boltun/src/stdafx.h b/plugins/Boltun/src/stdafx.h index e75e59ffdd..635d36b2d0 100644 --- a/plugins/Boltun/src/stdafx.h +++ b/plugins/Boltun/src/stdafx.h @@ -26,6 +26,7 @@ #include <fstream>
#include <assert.h>
+#include <algorithm>
#include <string>
#include <list>
|