Skip to content

Commit

Permalink
Публичная версия 1.21
Browse files Browse the repository at this point in the history
Редкий креш, добавлена операция деления числа на разряды при отображении.
  • Loading branch information
gmax79 committed Aug 18, 2021
1 parent 4b0b5aa commit 02844fd
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
10 changes: 7 additions & 3 deletions help/tortilla.htm
Expand Up @@ -1259,16 +1259,20 @@ <h4>#math</h4>
<li><div class="t">/</div> деление</li>
<li><div class="t">+</div> сложение</li>
<li><div class="t">-</div> вычитание</li>
<li><div class="t">%</div> деление на разряды</li>
</ul>
Синтаксис команды:<br>
<div class="t">#math targetvar 'operand1 op operand2'</div><br>
- targetvar - имя переменной, куда нужно записать результат.<br>
- operand1 и operand2 - это число или имя переменной, начинающейся со знака $.<br>
- op - сама операция умножения, деления, сложения или вычитания.<br><br>
- operand1 и operand2 - это число или имя переменной, начинающейся со знака $. ( Для <div class="t">%</div> operand1 не указывается )<br>
- op - сама операция умножения, деления, сложения, вычитания или деления на разряды.<br><br>
Примеры:
<div class="ee">#math a $b+1<br>
#math d $c/$b
#math d $c/$b<br><br>
#math f %$x - если $x=12345678, в f запишется строка '12 345 678'
</div>
<div class="cmd">Важно!</div> Часть с операндами и операцией не должна содержать пробелы. Она должна быть единым блоком.<br>

См.также: <a href="#var" class="cmd">#var</a>, <a href="#if" class="cmd">#if</a>, <a href="#strop" class="cmd">#strop</a>.
<hr>
<a name="mccp"></a>
Expand Down
9 changes: 4 additions & 5 deletions mudclient/res/mudclient.rc
Expand Up @@ -494,7 +494,6 @@ BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 249
TOPMARGIN, 7
BOTTOMMARGIN, 63
END

IDD_MODE, DIALOG
Expand Down Expand Up @@ -577,8 +576,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,20,0,0
PRODUCTVERSION 1,20,0,0
FILEVERSION 1,21,0,0
PRODUCTVERSION 1,21,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -594,12 +593,12 @@ BEGIN
BLOCK "080004b0"
BEGIN
VALUE "FileDescription", "Tortilla Mud Client"
VALUE "FileVersion", "1.20.0.0"
VALUE "FileVersion", "1.21.0.0"
VALUE "InternalName", "Tortilla"
VALUE "LegalCopyright", "http://tmud.github.io"
VALUE "OriginalFilename", "tortilla.exe"
VALUE "ProductName", "Tortilla Mud Client"
VALUE "ProductVersion", "1.20.0.0"
VALUE "ProductVersion", "1.21.0.0"
END
END
BLOCK "VarFileInfo"
Expand Down
1 change: 1 addition & 0 deletions mudclient/src/common/common.cpp
Expand Up @@ -117,6 +117,7 @@ bool w2int(const tstring& str, int *value)
*value = _wtoi(str.c_str());
return true;
}

void int2w(int value, tstring* str)
{
wchar_t buffer[16];
Expand Down
29 changes: 28 additions & 1 deletion mudclient/src/logicHelper.cpp
Expand Up @@ -6,7 +6,7 @@
LogicHelper::LogicHelper()
{
m_if_regexp.setRegExp(L"^([^ =~!<>]*) *(=|==|!=|~=|<>|<|>|<=|>=) *([^ =~!<>]*)$", true);
m_math_regexp.setRegExp(L"^([^+-/*]*) *([+-/*]) *([^+-/*]*)$", true);
m_math_regexp.setRegExp(L"^([^+/*%]*) *([+-/*%]) *([^+/*%]*)$", true);
m_params_regexp.setRegExp(L"['{\"]?(.*['}\"]?[^'}\"])", true);
}

Expand Down Expand Up @@ -282,6 +282,32 @@ LogicHelper::MathResult LogicHelper::mathOp(const tstring& expr, tstring* result
tstring_trim(&p2);
}

if ( op == L"%" && p1.empty() && isInt( p2 ) )
{
result->clear();
int len = p2.length();
const tchar* p = p2.c_str();
if (*p == L'-') { p++; len--; }

int first = len % 3;
result->append(p, first);
p += first;

for (int count = len/3; count > 0; count--)
{
if ( !result->empty() )
result->append(L" ");
result->append( p, 3 );
p += 3;
}

p = p2.c_str();
if ( *p == L'-' )
result->insert(0, L"-");

return LogicHelper::MATH_SUCCESS;
}

if (tortilla::getVars()->processVarsStrong(&p1, true) && tortilla::getVars()->processVarsStrong(&p2, true))
{
if (isInt(p1) && isInt(p2))
Expand All @@ -301,6 +327,7 @@ LogicHelper::MathResult LogicHelper::mathOp(const tstring& expr, tstring* result
result->assign(buffer);
return LogicHelper::MATH_SUCCESS;
}

return LogicHelper::MATH_ERROR;
}
return LogicHelper::MATH_VARNOTEXIST;
Expand Down
2 changes: 1 addition & 1 deletion mudclient/src/plugins/pluginsParseData.h
Expand Up @@ -33,7 +33,7 @@ class PluginsParseData
std::vector<PluginViewString*> plugins_strings;
int selected;
public:
PluginsParseData(parseData *data, triggerParseData *trdata) : buffer(256), pdata(data), tdata(trdata), selected(-1) { convert(); }
PluginsParseData(parseData *data, triggerParseData *trdata) : buffer(1024), pdata(data), tdata(trdata), selected(-1) { convert(); }
~PluginsParseData() { convert_back(); std::for_each(plugins_strings.begin(), plugins_strings.end(), [](PluginViewString*s) { delete s; }); }
int size() const { return plugins_strings.size(); }
int getindex() const { return selected+1; }
Expand Down
4 changes: 2 additions & 2 deletions mudclient/src/stdafx.h
@@ -1,8 +1,8 @@
#pragma once

#define TORTILLA_VERSION_BASE L"1.20"
#define TORTILLA_VERSION_BASE L"1.21"
#define TORTILLA_VERSION_MAJOR 1
#define TORTILLA_VERSION_MINOR 20
#define TORTILLA_VERSION_MINOR 21

#ifdef _DEBUG
#define TORTILLA_VERSION TORTILLA_VERSION_BASE" debug"
Expand Down

0 comments on commit 02844fd

Please sign in to comment.