mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-11 21:03:05 +08:00
+enh: RegExpr enhancements
This commit is contained in:
parent
0512e96c51
commit
789c87e17f
@ -341,6 +341,7 @@
|
||||
<ClCompile Include="oniguruma\src\regenc.c" />
|
||||
<ClCompile Include="oniguruma\src\regerror.c" />
|
||||
<ClCompile Include="oniguruma\src\regexec.c" />
|
||||
<ClCompile Include="oniguruma\src\regext.c" />
|
||||
<ClCompile Include="oniguruma\src\reggnu.c" />
|
||||
<ClCompile Include="oniguruma\src\regparse.c" />
|
||||
<ClCompile Include="oniguruma\src\regsyntax.c" />
|
||||
|
||||
@ -183,6 +183,9 @@
|
||||
<ClCompile Include="src\ChangeHistory.cxx">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="oniguruma\src\regext.c">
|
||||
<Filter>oniguruma\src</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\ILexer.h">
|
||||
|
||||
@ -82,18 +82,16 @@ static void SetSimpleOptions(OnigOptionType& onigOptions, EOLmode /*eolMode*/,
|
||||
|
||||
// Notepad3 forced options
|
||||
ONIG_OPTION_ON(onigOptions, ONIG_OPTION_NEGATE_SINGLELINE);
|
||||
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_SINGLELINE);
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_POSIX_REGION);
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_EXTEND);
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_SINGLELINE);
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_FIND_LONGEST);
|
||||
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_MATCH_WHOLE_STRING);
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_SYN_OP_DOT_ANYCHAR); // (!!!)
|
||||
//ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_ASCII_RANGE);
|
||||
//ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_CAPTURE_GROUP);
|
||||
|
||||
// dynamic options
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_MATCH_WHOLE_STRING);
|
||||
|
||||
//switch (eolMode) {
|
||||
// case EOLmode::CR:
|
||||
// case EOLmode::LF:
|
||||
@ -102,14 +100,12 @@ static void SetSimpleOptions(OnigOptionType& onigOptions, EOLmode /*eolMode*/,
|
||||
// break;
|
||||
//}
|
||||
|
||||
bool const bDotMatchesAll = FlagSet(searchFlags, FindOption::DotMatchAll);
|
||||
|
||||
if (bDotMatchesAll) {
|
||||
ONIG_OPTION_ON(onigOptions, ONIG_SYN_OP_DOT_ANYCHAR);
|
||||
if (FlagSet(searchFlags, FindOption::DotMatchAll)) {
|
||||
//~ONIG_OPTION_ON(onigOptions, ONIG_SYN_OP_DOT_ANYCHAR);
|
||||
ONIG_OPTION_ON(onigOptions, ONIG_OPTION_MULTILINE);
|
||||
}
|
||||
else {
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_SYN_OP_DOT_ANYCHAR);
|
||||
//~ONIG_OPTION_OFF(onigOptions, ONIG_SYN_OP_DOT_ANYCHAR);
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_MULTILINE);
|
||||
}
|
||||
|
||||
@ -124,36 +120,40 @@ static void SetSimpleOptions(OnigOptionType& onigOptions, EOLmode /*eolMode*/,
|
||||
}
|
||||
else {
|
||||
}
|
||||
|
||||
}
|
||||
// ============================================================================
|
||||
|
||||
|
||||
#define NP3_ONIG_SYNTAX_FLAVOR (ONIG_SYNTAX_DEFAULT) // default is: ONIG_SYNTAX_ONIGURUMA
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class OnigurumaRegExEngine : public RegexSearchBase
|
||||
{
|
||||
public:
|
||||
|
||||
explicit OnigurumaRegExEngine(CharClassify* /*charClassTable*/)
|
||||
: m_OnigSyntax(*ONIG_SYNTAX_DEFAULT)
|
||||
: m_OnigSyntax(*NP3_ONIG_SYNTAX_FLAVOR)
|
||||
, m_CmplOptions(ONIG_OPTION_DEFAULT)
|
||||
, m_RegExpr(nullptr)
|
||||
, m_Region({0,0,nullptr,nullptr,nullptr})
|
||||
, m_RangeBeg(-1)
|
||||
, m_RangeEnd(-1)
|
||||
, m_ErrorInfo()
|
||||
, m_Result(ONIG_MISMATCH)
|
||||
, m_MatchPos(ONIG_MISMATCH)
|
||||
, m_MatchLen(0)
|
||||
{
|
||||
m_OnigSyntax.op |= ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END; // xcluded from ONIG_SYNTAX_DEFAULT ?
|
||||
onig_initialize(s_UsedEncodingsTypes, _ARRAYSIZE(s_UsedEncodingsTypes));
|
||||
///onig_set_default_syntax(ONIG_SYNTAX_ONIGURUMA); // std is: ONIG_SYNTAX_ONIGURUMA
|
||||
onig_set_default_syntax(NP3_ONIG_SYNTAX_FLAVOR); // std is: ONIG_SYNTAX_ONIGURUMA
|
||||
onig_region_init(&m_Region);
|
||||
}
|
||||
|
||||
~OnigurumaRegExEngine() override
|
||||
{
|
||||
onig_region_free(&m_Region, 0); /* 1:free self, 0:free contents only */
|
||||
onig_free(m_RegExpr);
|
||||
clear();
|
||||
onig_end();
|
||||
}
|
||||
|
||||
@ -166,9 +166,11 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
std::string &translateRegExpr(std::string ®ExprStr, bool wholeWord, bool wordStart, EndOfLine eolMode, OnigOptionType &rxOptions);
|
||||
void clear();
|
||||
|
||||
std::string& convertReplExpr(std::string& replStr);
|
||||
std::string translateRegExpr(const std::string & regExprStr, bool wholeWord, bool wordStart, EndOfLine eolMode, OnigOptionType & rxOptions);
|
||||
|
||||
std::string convertReplExpr(const std::string & replStr);
|
||||
|
||||
//void regexFindAndReplace(std::string& inputStr_inout, const std::string& patternStr, const std::string& replStr);
|
||||
|
||||
@ -181,8 +183,12 @@ private:
|
||||
OnigRegex m_RegExpr;
|
||||
OnigRegion m_Region;
|
||||
|
||||
Sci::Position m_RangeBeg;
|
||||
Sci::Position m_RangeEnd;
|
||||
|
||||
char m_ErrorInfo[ONIG_MAX_ERROR_MESSAGE_LEN];
|
||||
|
||||
OnigPos m_Result;
|
||||
Sci::Position m_MatchPos;
|
||||
Sci::Position m_MatchLen;
|
||||
|
||||
@ -273,6 +279,7 @@ Sci::Position OnigurumaRegExEngine::FindText(Document* doc, Sci::Position minPos
|
||||
return SciPos(-1);
|
||||
}
|
||||
|
||||
auto const docBegPos = SciPos(0);
|
||||
auto const docEndPos = SciPos(doc->Length());
|
||||
EOLmode const eolMode = static_cast<EOLmode>(doc->eolMode);
|
||||
|
||||
@ -283,48 +290,53 @@ Sci::Position OnigurumaRegExEngine::FindText(Document* doc, Sci::Position minPos
|
||||
minPos = doc->MovePositionOutsideChar(minPos + (findForward ? 0 : -1), increment, false);
|
||||
maxPos = doc->MovePositionOutsideChar(maxPos, increment, false);
|
||||
|
||||
|
||||
Sci::Position const rangeBeg = (findForward) ? minPos : maxPos;
|
||||
Sci::Position const rangeEnd = (findForward) ? maxPos : minPos;
|
||||
Sci::Position const rangeLen = (rangeEnd - rangeBeg);
|
||||
|
||||
OnigOptionType onigOptions;
|
||||
SetSimpleOptions(onigOptions, eolMode, caseSensitive, findForward, searchFlags);
|
||||
ONIG_OPTION_ON(onigOptions, (rangeBeg > 0) ? ONIG_OPTION_NOTBOL : ONIG_OPTION_NONE);
|
||||
ONIG_OPTION_ON(onigOptions, (rangeBeg > docBegPos) ? ONIG_OPTION_NOTBOL : ONIG_OPTION_NONE);
|
||||
ONIG_OPTION_ON(onigOptions, (rangeEnd < docEndPos) ? ONIG_OPTION_NOTEOL : ONIG_OPTION_NONE);
|
||||
|
||||
std::string sPattern(pattern);
|
||||
std::string const & sRegExprStrg = translateRegExpr(sPattern, word, wordStart, doc->eolMode, onigOptions);
|
||||
std::string const sRegExprStrg = translateRegExpr(pattern, word, wordStart, doc->eolMode, onigOptions);
|
||||
|
||||
bool const bReCompile = (m_RegExpr == nullptr) || (m_CmplOptions != onigOptions) || (m_RegExprStrg.compare(sRegExprStrg) != 0);
|
||||
|
||||
if (bReCompile) {
|
||||
m_RegExprStrg.clear();
|
||||
clear();
|
||||
m_RegExprStrg = sRegExprStrg;
|
||||
m_CmplOptions = onigOptions;
|
||||
m_RangeBeg = rangeBeg;
|
||||
m_RangeEnd = rangeEnd;
|
||||
m_ErrorInfo[0] = '\0';
|
||||
try {
|
||||
OnigErrorInfo einfo;
|
||||
onig_free(m_RegExpr);
|
||||
|
||||
//OnigEncoding const onigEncType = ONIG_ENCODING_UTF8;
|
||||
OnigEncoding const onigEncType = (eolMode == EOLmode::LF) ? ONIG_ENCODING_UTF8 :
|
||||
((eolMode == EOLmode::CR) ? ONIG_ENCODING_UTF8_CR : ONIG_ENCODING_UTF8_CRLF);
|
||||
int res = onig_new(&m_RegExpr, UCharCPtr(m_RegExprStrg.c_str()), UCharCPtr(m_RegExprStrg.c_str() + m_RegExprStrg.length()),
|
||||
m_CmplOptions, onigEncType, &m_OnigSyntax, &einfo);
|
||||
|
||||
int const res = onig_new(&m_RegExpr, UCharCPtr(m_RegExprStrg.c_str()), UCharCPtr(m_RegExprStrg.c_str() + m_RegExprStrg.length()),
|
||||
m_CmplOptions, onigEncType, &m_OnigSyntax, &einfo);
|
||||
|
||||
if (res != ONIG_NORMAL) {
|
||||
onig_error_code_to_str(UCharPtr(m_ErrorInfo), res, &einfo);
|
||||
clear();
|
||||
return SciPos(-2); // -1 is normally used for not found, -2 is used here for invalid regex
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
clear();
|
||||
return SciPos(-2);
|
||||
}
|
||||
} else {
|
||||
// check if already searched for
|
||||
if ((m_RangeBeg == rangeBeg) && (m_RangeEnd == rangeEnd)) {
|
||||
*length = m_MatchLen;
|
||||
return m_MatchPos;
|
||||
}
|
||||
}
|
||||
|
||||
m_MatchPos = SciPos(ONIG_MISMATCH); // not found
|
||||
m_MatchLen = SciPos(0);
|
||||
|
||||
// --- search document range for pattern match ---
|
||||
// !!! Performance issue: Scintilla: moving Gap needs memcopy - high costs for find/replace in large document
|
||||
auto const docBegPtr = UCharCPtr(doc->RangePointer(0, docEndPos));
|
||||
@ -332,31 +344,34 @@ Sci::Position OnigurumaRegExEngine::FindText(Document* doc, Sci::Position minPos
|
||||
auto const rangeBegPtr = UCharCPtr(doc->RangePointer(rangeBeg, rangeLen));
|
||||
auto const rangeEndPtr = UCharCPtr(doc->RangePointer(rangeEnd, 0));
|
||||
|
||||
OnigPos result = ONIG_MISMATCH;
|
||||
m_Result = ONIG_MISMATCH;
|
||||
try {
|
||||
onig_region_free(&m_Region, 0); /* 1:free self, 0:free contents only */
|
||||
onig_region_init(&m_Region);
|
||||
|
||||
if (findForward)
|
||||
result = onig_search(m_RegExpr, docBegPtr, docEndPtr, rangeBegPtr, rangeEndPtr, &m_Region, onigOptions);
|
||||
m_Result = onig_search(m_RegExpr, docBegPtr, docEndPtr, rangeBegPtr, rangeEndPtr, &m_Region, onigOptions);
|
||||
else // X //
|
||||
result = onig_search(m_RegExpr, docBegPtr, docEndPtr, rangeEndPtr, rangeBegPtr, &m_Region, onigOptions);
|
||||
m_Result = onig_search(m_RegExpr, docBegPtr, docEndPtr, rangeEndPtr, rangeBegPtr, &m_Region, onigOptions);
|
||||
}
|
||||
catch (...) {
|
||||
return SciPos(-3); // -1 is normally used for not found, -3 is used here for exception
|
||||
}
|
||||
|
||||
if (result < ONIG_MISMATCH) {
|
||||
onig_error_code_to_str(UCharPtr(m_ErrorInfo), result);
|
||||
if (m_Result < ONIG_MISMATCH) {
|
||||
onig_error_code_to_str(UCharPtr(m_ErrorInfo), m_Result);
|
||||
return SciPos(-3);
|
||||
}
|
||||
|
||||
if ((result >= 0) && (rangeBegPtr <= rangeEndPtr))
|
||||
if ((m_Result >= 0) && (m_Region.num_regs >= 1))
|
||||
{
|
||||
//~m_MatchPos = SciPos(result); //
|
||||
//~m_MatchPos = SciPos(m_Result); //
|
||||
m_MatchPos = SciPos(m_Region.beg[0]);
|
||||
//~m_MatchLen = SciPos(m_Region.end[0] - result);
|
||||
m_MatchLen = SciPos(m_Region.end[0]) - SciPos(m_Region.beg[0]);
|
||||
//~m_MatchLen = SciPos(m_Region.end[0] - m_Result);
|
||||
m_MatchLen = SciPos(m_Region.end[0]) - m_MatchPos;
|
||||
} else {
|
||||
m_MatchPos = SciPos(ONIG_MISMATCH);
|
||||
m_MatchLen = SciPos(0);
|
||||
}
|
||||
|
||||
//NOTE: potential 64-bit-size issue at interface here:
|
||||
@ -514,24 +529,37 @@ void OnigurumaRegExEngine::regexFindAndReplace(std::string& inputStr_inout, cons
|
||||
*/
|
||||
|
||||
|
||||
void OnigurumaRegExEngine::clear() {
|
||||
m_RegExprStrg.clear();
|
||||
onig_region_free(&m_Region, 0); /* 1:free self, 0:free contents only */
|
||||
onig_free(m_RegExpr);
|
||||
m_RegExpr = nullptr;
|
||||
// reset
|
||||
m_RangeBeg = SciPos(ONIG_MISMATCH);
|
||||
m_RangeEnd = SciPos(ONIG_MISMATCH);
|
||||
m_Result = ONIG_MISMATCH;
|
||||
m_MatchPos = SciPos(ONIG_MISMATCH);
|
||||
m_MatchLen = SciPos(0);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
std::string &OnigurumaRegExEngine::translateRegExpr(std::string ®ExprStr, bool wholeWord, bool wordStart, EndOfLine eolMode, OnigOptionType & /*rxOptions*/) {
|
||||
std::string tmpStr;
|
||||
bool bUseTmpStrg = false;
|
||||
|
||||
std::string OnigurumaRegExEngine::translateRegExpr(const std::string & regExprStr, bool wholeWord, bool wordStart, EndOfLine eolMode, OnigOptionType & /*rxOptions*/)
|
||||
{
|
||||
std::string transRegExpr;
|
||||
|
||||
if (wholeWord || wordStart) { // push '\b' at the begin of regexpr
|
||||
tmpStr.push_back('\\');
|
||||
tmpStr.push_back('b');
|
||||
tmpStr.append(regExprStr);
|
||||
transRegExpr.push_back('\\');
|
||||
transRegExpr.push_back('b');
|
||||
transRegExpr.append(regExprStr);
|
||||
if (wholeWord) { // push '\b' at the end of regexpr
|
||||
tmpStr.push_back('\\');
|
||||
tmpStr.push_back('b');
|
||||
transRegExpr.push_back('\\');
|
||||
transRegExpr.push_back('b');
|
||||
}
|
||||
replaceAll(tmpStr, ".", R"(\w)");
|
||||
bUseTmpStrg = true;
|
||||
replaceAll(transRegExpr, ".", R"(\w)");
|
||||
}
|
||||
else {
|
||||
tmpStr.append(regExprStr);
|
||||
transRegExpr.append(regExprStr);
|
||||
}
|
||||
|
||||
//if (wholeString) {
|
||||
@ -542,11 +570,10 @@ std::string &OnigurumaRegExEngine::translateRegExpr(std::string ®ExprStr, boo
|
||||
|
||||
// Oniguruma supports LTGT word boundary by: ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END
|
||||
//
|
||||
//~replaceAll(tmpStr, R"(\<)", R"((?<!\w)(?=\w))"); // word begin
|
||||
//~replaceAll(tmpStr, R"(\(?<!\w)(?=\w))", R"(\\<)"); // esc'd
|
||||
//~replaceAll(tmpStr, R"(\>)", R"((?<=\w)(?!\w))"); // word end
|
||||
//~replaceAll(tmpStr, R"(\(?<=\w)(?!\w))", R"(\\>)"); // esc'd
|
||||
//~bUseTmpStrg = true;
|
||||
//~replaceAll(transRegExpr, R"(\<)", R"((?<!\w)(?=\w))"); // word begin
|
||||
//~replaceAll(transRegExpr, R"(\(?<!\w)(?=\w))", R"(\\<)"); // esc'd
|
||||
//~replaceAll(transRegExpr, R"(\>)", R"((?<=\w)(?!\w))"); // word end
|
||||
//~replaceAll(transRegExpr, R"(\(?<=\w)(?!\w))", R"(\\>)"); // esc'd
|
||||
|
||||
|
||||
// EOL modes
|
||||
@ -561,16 +588,15 @@ std::string &OnigurumaRegExEngine::translateRegExpr(std::string ®ExprStr, boo
|
||||
break;
|
||||
}
|
||||
|
||||
if (bUseTmpStrg) { std::swap(regExprStr, tmpStr); }
|
||||
|
||||
return regExprStr;
|
||||
return transRegExpr;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
std::string& OnigurumaRegExEngine::convertReplExpr(std::string& replStr)
|
||||
std::string OnigurumaRegExEngine::convertReplExpr(const std::string& replStr)
|
||||
{
|
||||
std::string tmpStr;
|
||||
std::string convReplExpr;
|
||||
|
||||
for (size_t i = 0; i < replStr.length(); ++i) {
|
||||
char ch = replStr[i];
|
||||
if (ch == '\\') {
|
||||
@ -578,36 +604,36 @@ std::string& OnigurumaRegExEngine::convertReplExpr(std::string& replStr)
|
||||
if (ch >= '1' && ch <= '9') {
|
||||
// former behavior convenience:
|
||||
// change "\\<n>" to deelx's group reference ($<n>)
|
||||
tmpStr.push_back('$');
|
||||
tmpStr.push_back(ch);
|
||||
convReplExpr.push_back('$');
|
||||
convReplExpr.push_back(ch);
|
||||
continue;
|
||||
}
|
||||
switch (ch) {
|
||||
// check for escape seq:
|
||||
case 'a':
|
||||
tmpStr.push_back('\a');
|
||||
convReplExpr.push_back('\a');
|
||||
break;
|
||||
case 'b':
|
||||
tmpStr.push_back('\x1B');
|
||||
convReplExpr.push_back('\x1B');
|
||||
break;
|
||||
case 'f':
|
||||
tmpStr.push_back('\f');
|
||||
convReplExpr.push_back('\f');
|
||||
break;
|
||||
case 'n':
|
||||
tmpStr.push_back('\n');
|
||||
convReplExpr.push_back('\n');
|
||||
break;
|
||||
case 'r':
|
||||
tmpStr.push_back('\r');
|
||||
convReplExpr.push_back('\r');
|
||||
break;
|
||||
case 't':
|
||||
tmpStr.push_back('\t');
|
||||
convReplExpr.push_back('\t');
|
||||
break;
|
||||
case 'v':
|
||||
tmpStr.push_back('\v');
|
||||
convReplExpr.push_back('\v');
|
||||
break;
|
||||
case '\\':
|
||||
tmpStr.push_back('\\'); // preserve escd "\"
|
||||
tmpStr.push_back('\\');
|
||||
convReplExpr.push_back('\\'); // preserve escd "\"
|
||||
convReplExpr.push_back('\\');
|
||||
break;
|
||||
case 'x':
|
||||
case 'u':
|
||||
@ -646,31 +672,30 @@ std::string& OnigurumaRegExEngine::convertReplExpr(std::string& replStr)
|
||||
if (val[0]) {
|
||||
val[1] = 0;
|
||||
WideCharToMultiByte(CP_UTF8, 0, val, -1, buf, ARRAYSIZE(val), nullptr, nullptr);
|
||||
tmpStr.push_back(*pch++);
|
||||
convReplExpr.push_back(*pch++);
|
||||
while (*pch)
|
||||
tmpStr.push_back(*pch++);
|
||||
convReplExpr.push_back(*pch++);
|
||||
}
|
||||
else
|
||||
tmpStr.push_back(ch); // unknown hex seq
|
||||
convReplExpr.push_back(ch); // unknown hex seq
|
||||
}
|
||||
else
|
||||
tmpStr.push_back(ch); // unknown hex seq
|
||||
convReplExpr.push_back(ch); // unknown hex seq
|
||||
}
|
||||
break;
|
||||
|
||||
default: // unknown ctrl seq
|
||||
tmpStr.push_back('\\'); // revert
|
||||
tmpStr.push_back(ch);
|
||||
convReplExpr.push_back('\\'); // revert
|
||||
convReplExpr.push_back(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
tmpStr.push_back(ch);
|
||||
convReplExpr.push_back(ch);
|
||||
}
|
||||
} //for
|
||||
|
||||
std::swap(replStr,tmpStr);
|
||||
return replStr;
|
||||
return convReplExpr;
|
||||
}
|
||||
// ============================================================================
|
||||
|
||||
@ -688,7 +713,7 @@ public:
|
||||
|
||||
explicit SimpleRegExEngine(const EOLmode eolMode)
|
||||
: m_EOLmode(eolMode)
|
||||
, m_OnigSyntax(*ONIG_SYNTAX_DEFAULT)
|
||||
, m_OnigSyntax(*NP3_ONIG_SYNTAX_FLAVOR)
|
||||
, m_Options(ONIG_OPTION_DEFAULT)
|
||||
, m_RegExpr(nullptr)
|
||||
, m_Region({ 0,0,nullptr,nullptr,nullptr })
|
||||
@ -698,6 +723,7 @@ public:
|
||||
{
|
||||
m_OnigSyntax.op |= ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END; // xcluded from ONIG_SYNTAX_DEFAULT ?
|
||||
onig_initialize(s_UsedEncodingsTypes, _ARRAYSIZE(s_UsedEncodingsTypes));
|
||||
onig_set_default_syntax(NP3_ONIG_SYNTAX_FLAVOR); // std is: ONIG_SYNTAX_ONIGURUMA
|
||||
onig_region_init(&m_Region);
|
||||
}
|
||||
|
||||
@ -775,8 +801,7 @@ OnigPos SimpleRegExEngine::Find(const OnigUChar* pattern, const OnigUChar* docum
|
||||
const UChar* rangeEnd = strgEnd;
|
||||
|
||||
// start search
|
||||
OnigPos result = onig_search(m_RegExpr, strgBeg, strgEnd,
|
||||
rangeBeg, rangeEnd, &m_Region, m_Options);
|
||||
OnigPos result = onig_search(m_RegExpr, strgBeg, strgEnd, rangeBeg, rangeEnd, &m_Region, m_Options);
|
||||
|
||||
if (result < ONIG_MISMATCH) {
|
||||
//onig_error_code_to_str(m_ErrorInfo, result);
|
||||
@ -791,7 +816,7 @@ OnigPos SimpleRegExEngine::Find(const OnigUChar* pattern, const OnigUChar* docum
|
||||
//~m_MatchPos = result; //
|
||||
m_MatchPos = m_Region.beg[0];
|
||||
//~m_MatchLen = (m_Region.end[0] - result);
|
||||
m_MatchLen = (m_Region.end[0] - m_Region.beg[0]);
|
||||
m_MatchLen = m_Region.end[0] - m_MatchPos;
|
||||
}
|
||||
//else if (result == ONIG_MISMATCH) // not found
|
||||
//{
|
||||
|
||||
@ -146,8 +146,8 @@ OnigEncodingType OnigEncodingASCII_CR = {
|
||||
OnigEncodingType OnigEncodingASCII_CRLF = {
|
||||
onigenc_single_byte_mbc_enc_len,
|
||||
"US-ASCII", /* name */
|
||||
1, /* max enc length */
|
||||
1, /* min enc length */
|
||||
2, /* max enc length */
|
||||
2, /* min enc length */
|
||||
onigenc_is_mbc_newline_0x0d_0x0a,
|
||||
onigenc_single_byte_mbc_to_code,
|
||||
onigenc_single_byte_code_to_mbclen,
|
||||
|
||||
@ -7,7 +7,7 @@ import sys
|
||||
import re
|
||||
|
||||
POSIX_LIST = [
|
||||
'NEWLINE', 'Alpha', 'Blank', 'Cntrl', 'Digit', 'Graph', 'Lower',
|
||||
'NEWLINE', 'Alpha', 'Blank', 'Cntrl', 'Digit', 'Graph', 'Lower',
|
||||
'Print', 'PosixPunct', 'Space', 'Upper', 'XDigit', 'Word', 'Alnum',
|
||||
'ASCII'
|
||||
]
|
||||
|
||||
@ -195,9 +195,8 @@ ONIG_EXTERN OnigEncodingType OnigEncodingUTF8_CR;
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingUTF8_CRLF;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define ONIG_ENCODING_ASCII (&OnigEncodingASCII)
|
||||
#define ONIG_ENCODING_ASCII_CR (&OnigEncodingASCII_CR)
|
||||
#define ONIG_ENCODING_ASCII_CRLF (&OnigEncodingASCII_CRLF)
|
||||
#define ONIG_ENCODING_ISO_8859_1 (&OnigEncodingISO_8859_1)
|
||||
#define ONIG_ENCODING_ISO_8859_2 (&OnigEncodingISO_8859_2)
|
||||
#define ONIG_ENCODING_ISO_8859_3 (&OnigEncodingISO_8859_3)
|
||||
@ -214,8 +213,6 @@ ONIG_EXTERN OnigEncodingType OnigEncodingUTF8_CRLF;
|
||||
#define ONIG_ENCODING_ISO_8859_15 (&OnigEncodingISO_8859_15)
|
||||
#define ONIG_ENCODING_ISO_8859_16 (&OnigEncodingISO_8859_16)
|
||||
#define ONIG_ENCODING_UTF8 (&OnigEncodingUTF8)
|
||||
#define ONIG_ENCODING_UTF8_CR (&OnigEncodingUTF8_CR)
|
||||
#define ONIG_ENCODING_UTF8_CRLF (&OnigEncodingUTF8_CRLF)
|
||||
#define ONIG_ENCODING_UTF16_BE (&OnigEncodingUTF16_BE)
|
||||
#define ONIG_ENCODING_UTF16_LE (&OnigEncodingUTF16_LE)
|
||||
#define ONIG_ENCODING_UTF32_BE (&OnigEncodingUTF32_BE)
|
||||
@ -230,6 +227,14 @@ ONIG_EXTERN OnigEncodingType OnigEncodingUTF8_CRLF;
|
||||
#define ONIG_ENCODING_CP1251 (&OnigEncodingCP1251)
|
||||
#define ONIG_ENCODING_BIG5 (&OnigEncodingBIG5)
|
||||
#define ONIG_ENCODING_GB18030 (&OnigEncodingGB18030)
|
||||
#else // lean and mean
|
||||
#define ONIG_ENCODING_ASCII (&OnigEncodingASCII)
|
||||
#define ONIG_ENCODING_ASCII_CR (&OnigEncodingASCII_CR)
|
||||
#define ONIG_ENCODING_ASCII_CRLF (&OnigEncodingASCII_CRLF)
|
||||
#define ONIG_ENCODING_UTF8 (&OnigEncodingUTF8)
|
||||
#define ONIG_ENCODING_UTF8_CR (&OnigEncodingUTF8_CR)
|
||||
#define ONIG_ENCODING_UTF8_CRLF (&OnigEncodingUTF8_CRLF)
|
||||
#endif
|
||||
|
||||
#define ONIG_ENCODING_UNDEF ((OnigEncoding )0)
|
||||
|
||||
|
||||
@ -7076,7 +7076,7 @@ clear_optimize_info(regex_t* reg)
|
||||
|
||||
static void
|
||||
print_enc_string(FILE* fp, OnigEncoding enc,
|
||||
const UChar *s, const UChar *end)
|
||||
const UChar *s, const UChar *end)
|
||||
{
|
||||
if (ONIGENC_MBC_MINLEN(enc) > 1) {
|
||||
const UChar *p;
|
||||
@ -7106,7 +7106,7 @@ print_enc_string(FILE* fp, OnigEncoding enc,
|
||||
}
|
||||
}
|
||||
else { /* for UTF-8 */
|
||||
fputc((int )*s, fp);
|
||||
fputc((int )*s, fp);
|
||||
}
|
||||
s++;
|
||||
}
|
||||
@ -7251,7 +7251,7 @@ print_optimize_info(FILE* f, regex_t* reg)
|
||||
if (reg->map[i]) n++;
|
||||
|
||||
fprintf(f, "map: n=%d, dmin: %u, dmax: %u\n",
|
||||
n, reg->dist_min, reg->dist_max);
|
||||
n, reg->dist_min, reg->dist_max);
|
||||
if (n > 0) {
|
||||
c = 0;
|
||||
fputc('[', f);
|
||||
|
||||
@ -719,8 +719,7 @@ extern int
|
||||
onigenc_is_mbc_newline_0x0d_0x0a(const UChar* p, const UChar* end)
|
||||
{
|
||||
if (p < end) {
|
||||
//~if ((*p == CARRIAGE_RET) && (*(p+1) == NEWLINE_CODE)) return 1; // CRLF
|
||||
if ((*p == NEWLINE_CODE) || (*p == CARRIAGE_RET)) return 1; // LF|CR
|
||||
if ((*p == CARRIAGE_RET) && (*(p+1) == NEWLINE_CODE)) return 1; // CRLF
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -3059,7 +3059,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
|
||||
}
|
||||
|
||||
#ifdef USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE
|
||||
if (OPTON_FIND_LONGEST(options)) {
|
||||
if (OPTON_FIND_LONGEST(options)) {
|
||||
if (n > best_len) {
|
||||
if (n > msa->best_len) {
|
||||
best_len = n;
|
||||
@ -3080,10 +3080,10 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
|
||||
}
|
||||
}
|
||||
else {
|
||||
best_len = n;
|
||||
}
|
||||
#else
|
||||
best_len = n;
|
||||
}
|
||||
#else
|
||||
best_len = n;
|
||||
#endif
|
||||
|
||||
/* set region */
|
||||
@ -4656,8 +4656,8 @@ regset_search_body_position_lead(OnigRegSet* set,
|
||||
|
||||
static inline int
|
||||
regset_search_body_regex_lead(OnigRegSet* set,
|
||||
const UChar* str, const UChar* end,
|
||||
const UChar* start, const UChar* orig_range, OnigRegSetLead lead,
|
||||
const UChar* str, const UChar* end,
|
||||
const UChar* start, const UChar* orig_range, OnigRegSetLead lead,
|
||||
OnigOptionType option, OnigMatchParam* mps[], int* rmatch_pos)
|
||||
{
|
||||
int r;
|
||||
@ -4828,9 +4828,9 @@ onig_regset_search_with_param(OnigRegSet* set,
|
||||
goto match;
|
||||
}
|
||||
else goto finish; /* error */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
goto mismatch;
|
||||
}
|
||||
@ -4890,7 +4890,7 @@ onig_regset_search_with_param(OnigRegSet* set,
|
||||
|
||||
extern int
|
||||
onig_regset_search(OnigRegSet* set, const UChar* str, const UChar* end,
|
||||
const UChar* start, const UChar* range,
|
||||
const UChar* start, const UChar* range,
|
||||
OnigRegSetLead lead, OnigOptionType option, int* rmatch_pos)
|
||||
{
|
||||
int r;
|
||||
|
||||
202
scintilla/oniguruma/src/regext.c
Normal file
202
scintilla/oniguruma/src/regext.c
Normal file
@ -0,0 +1,202 @@
|
||||
/**********************************************************************
|
||||
regext.c - Oniguruma (regular expression library)
|
||||
**********************************************************************/
|
||||
/*-
|
||||
* Copyright (c) 2002-2019 K.Kosako
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "regint.h"
|
||||
|
||||
#if 0
|
||||
static void
|
||||
conv_ext0be32(const UChar* s, const UChar* end, UChar* conv)
|
||||
{
|
||||
while (s < end) {
|
||||
*conv++ = '\0';
|
||||
*conv++ = '\0';
|
||||
*conv++ = '\0';
|
||||
*conv++ = *s++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
conv_ext0le32(const UChar* s, const UChar* end, UChar* conv)
|
||||
{
|
||||
while (s < end) {
|
||||
*conv++ = *s++;
|
||||
*conv++ = '\0';
|
||||
*conv++ = '\0';
|
||||
*conv++ = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
conv_ext0be(const UChar* s, const UChar* end, UChar* conv)
|
||||
{
|
||||
while (s < end) {
|
||||
*conv++ = '\0';
|
||||
*conv++ = *s++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
conv_ext0le(const UChar* s, const UChar* end, UChar* conv)
|
||||
{
|
||||
while (s < end) {
|
||||
*conv++ = *s++;
|
||||
*conv++ = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
conv_swap4bytes(const UChar* s, const UChar* end, UChar* conv)
|
||||
{
|
||||
while (s < end) {
|
||||
*conv++ = s[3];
|
||||
*conv++ = s[2];
|
||||
*conv++ = s[1];
|
||||
*conv++ = s[0];
|
||||
s += 4;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
conv_swap2bytes(const UChar* s, const UChar* end, UChar* conv)
|
||||
{
|
||||
while (s < end) {
|
||||
*conv++ = s[1];
|
||||
*conv++ = s[0];
|
||||
s += 2;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
conv_encoding(OnigEncoding from, OnigEncoding to, const UChar* s, const UChar* end,
|
||||
UChar** conv, UChar** conv_end)
|
||||
{
|
||||
int len = (int )(end - s);
|
||||
|
||||
if (to == ONIG_ENCODING_UTF16_BE) {
|
||||
if (from == ONIG_ENCODING_ASCII || from == ONIG_ENCODING_ISO_8859_1) {
|
||||
*conv = (UChar* )xmalloc(len * 2);
|
||||
CHECK_NULL_RETURN_MEMERR(*conv);
|
||||
*conv_end = *conv + (len * 2);
|
||||
conv_ext0be(s, end, *conv);
|
||||
return 0;
|
||||
}
|
||||
else if (from == ONIG_ENCODING_UTF16_LE) {
|
||||
swap16:
|
||||
*conv = (UChar* )xmalloc(len);
|
||||
CHECK_NULL_RETURN_MEMERR(*conv);
|
||||
*conv_end = *conv + len;
|
||||
conv_swap2bytes(s, end, *conv);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (to == ONIG_ENCODING_UTF16_LE) {
|
||||
if (from == ONIG_ENCODING_ASCII || from == ONIG_ENCODING_ISO_8859_1) {
|
||||
*conv = (UChar* )xmalloc(len * 2);
|
||||
CHECK_NULL_RETURN_MEMERR(*conv);
|
||||
*conv_end = *conv + (len * 2);
|
||||
conv_ext0le(s, end, *conv);
|
||||
return 0;
|
||||
}
|
||||
else if (from == ONIG_ENCODING_UTF16_BE) {
|
||||
goto swap16;
|
||||
}
|
||||
}
|
||||
if (to == ONIG_ENCODING_UTF32_BE) {
|
||||
if (from == ONIG_ENCODING_ASCII || from == ONIG_ENCODING_ISO_8859_1) {
|
||||
*conv = (UChar* )xmalloc(len * 4);
|
||||
CHECK_NULL_RETURN_MEMERR(*conv);
|
||||
*conv_end = *conv + (len * 4);
|
||||
conv_ext0be32(s, end, *conv);
|
||||
return 0;
|
||||
}
|
||||
else if (from == ONIG_ENCODING_UTF32_LE) {
|
||||
swap32:
|
||||
*conv = (UChar* )xmalloc(len);
|
||||
CHECK_NULL_RETURN_MEMERR(*conv);
|
||||
*conv_end = *conv + len;
|
||||
conv_swap4bytes(s, end, *conv);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (to == ONIG_ENCODING_UTF32_LE) {
|
||||
if (from == ONIG_ENCODING_ASCII || from == ONIG_ENCODING_ISO_8859_1) {
|
||||
*conv = (UChar* )xmalloc(len * 4);
|
||||
CHECK_NULL_RETURN_MEMERR(*conv);
|
||||
*conv_end = *conv + (len * 4);
|
||||
conv_ext0le32(s, end, *conv);
|
||||
return 0;
|
||||
}
|
||||
else if (from == ONIG_ENCODING_UTF32_BE) {
|
||||
goto swap32;
|
||||
}
|
||||
}
|
||||
|
||||
return ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION;
|
||||
}
|
||||
#endif
|
||||
|
||||
extern int
|
||||
onig_new_deluxe(regex_t** reg, const UChar* pattern, const UChar* pattern_end,
|
||||
OnigCompileInfo* ci, OnigErrorInfo* einfo)
|
||||
{
|
||||
int r;
|
||||
UChar *cpat, *cpat_end;
|
||||
|
||||
if (IS_NOT_NULL(einfo)) einfo->par = (UChar* )NULL;
|
||||
|
||||
if (ci->pattern_enc != ci->target_enc) {
|
||||
return ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION;
|
||||
}
|
||||
else {
|
||||
cpat = (UChar* )pattern;
|
||||
cpat_end = (UChar* )pattern_end;
|
||||
}
|
||||
|
||||
*reg = (regex_t* )xmalloc(sizeof(regex_t));
|
||||
if (IS_NULL(*reg)) {
|
||||
r = ONIGERR_MEMORY;
|
||||
goto err2;
|
||||
}
|
||||
|
||||
r = onig_reg_init(*reg, ci->option, ci->case_fold_flag, ci->target_enc,
|
||||
ci->syntax);
|
||||
if (r != 0) goto err;
|
||||
|
||||
r = onig_compile(*reg, cpat, cpat_end, einfo);
|
||||
if (r != 0) {
|
||||
err:
|
||||
onig_free(*reg);
|
||||
*reg = NULL;
|
||||
}
|
||||
|
||||
err2:
|
||||
if (cpat != pattern) xfree(cpat);
|
||||
|
||||
return r;
|
||||
}
|
||||
@ -5172,10 +5172,10 @@ is_posix_bracket_start(UChar* from, UChar* to, OnigEncoding enc)
|
||||
p = from;
|
||||
while (p < to) {
|
||||
x = ONIGENC_MBC_TO_CODE(enc, p, to);
|
||||
p += enclen(enc, p);
|
||||
p += enclen(enc, p);
|
||||
if (x == ':') {
|
||||
if (p < to) {
|
||||
x = ONIGENC_MBC_TO_CODE(enc, p, to);
|
||||
x = ONIGENC_MBC_TO_CODE(enc, p, to);
|
||||
if (x == ']') {
|
||||
if (n == 0) return FALSE;
|
||||
else return TRUE;
|
||||
@ -5183,13 +5183,13 @@ is_posix_bracket_start(UChar* from, UChar* to, OnigEncoding enc)
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else if (x == '^' && n == 0) {
|
||||
;
|
||||
}
|
||||
else if (! ONIGENC_IS_CODE_ALPHA(enc, x)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
n += 1;
|
||||
}
|
||||
@ -6666,8 +6666,8 @@ prs_posix_bracket(CClassNode* cc, UChar** src, UChar* end, ParseEnv* env)
|
||||
}
|
||||
}
|
||||
|
||||
return ONIGERR_INVALID_POSIX_BRACKET_TYPE;
|
||||
}
|
||||
return ONIGERR_INVALID_POSIX_BRACKET_TYPE;
|
||||
}
|
||||
|
||||
static int
|
||||
fetch_char_property_to_ctype(UChar** src, UChar* end, ParseEnv* env)
|
||||
|
||||
@ -223,7 +223,7 @@ onig_posix_regexec(onig_posix_regex_t* reg, const char* str, size_t nmatch,
|
||||
ENC_STRING_LEN(ONIG_C(reg)->enc, str, len);
|
||||
end = (UChar* )(str + len);
|
||||
r = onig_search(ONIG_C(reg), (UChar* )str, end, (UChar* )str, end,
|
||||
(OnigRegion* )pm, options);
|
||||
(OnigRegion* )pm, options);
|
||||
|
||||
if (r >= 0) {
|
||||
r = 0; /* Match */
|
||||
|
||||
@ -5888,8 +5888,6 @@ static char* _GetReplaceString(HWND hwnd, CLPCEDITFINDREPLACE lpefr, int* iRepla
|
||||
static DocPos _FindInTarget(LPCWSTR wchFind, int sFlags,
|
||||
DocPos* begin, DocPos* end, bool bForceNext, FR_UPD_MODES fMode)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(bForceNext);
|
||||
|
||||
static char chFind[8192] = { '\0' }; // max find buffer
|
||||
|
||||
DocPos iPos = -1LL; // not found
|
||||
@ -6606,7 +6604,8 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
|
||||
DocPos end = Sci_GetDocEndPosition();
|
||||
|
||||
LPCWSTR wchFind = _EditGetFindStrg(s_pEfrData->hwnd, s_pEfrData, false);
|
||||
DocPos const iPos = _FindInTarget(wchFind, (int)(s_pEfrData->fuFlags), &start, &end, false, FRMOD_NORM);
|
||||
DocPos const iPos = _FindInTarget(wchFind, (int)(s_pEfrData->fuFlags), &start, &end, false, FRMOD_NORM);
|
||||
|
||||
if (iPos >= 0) {
|
||||
if (s_bIsReplaceDlg) {
|
||||
SciCall_ScrollRange(end, iPos);
|
||||
@ -7077,7 +7076,7 @@ bool EditFindNext(HWND hwnd, const LPEDITFINDREPLACE lpefr, bool bExtendSelectio
|
||||
|
||||
DocPos const iDocEndPos = Sci_GetDocEndPosition();
|
||||
|
||||
EditSetCaretToSelectionEnd(); // fluent swittch between Prev/Next
|
||||
EditSetCaretToSelectionEnd(); // fluent switch between Prev/Next
|
||||
DocPos start = SciCall_GetCurrentPos();
|
||||
DocPos end = iDocEndPos;
|
||||
|
||||
|
||||
@ -12613,6 +12613,39 @@ static unsigned __stdcall FileChangeObserver(void * pArg) {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
static void StopFileChangeObserver(HANDLE* phObserverThread)
|
||||
{
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 6258)
|
||||
|
||||
if (IS_VALID_HANDLE(*phObserverThread)) {
|
||||
if (IS_VALID_HANDLE(s_hEventObserverDone)) {
|
||||
DWORD const wait = SignalObjectAndWait(s_hEventObserverDone, *phObserverThread,
|
||||
/*INFINITE*/ (dwObservingTimeout << 1), FALSE);
|
||||
if (wait == WAIT_OBJECT_0) {
|
||||
CloseHandle(*phObserverThread); // ok
|
||||
}
|
||||
else if (wait == WAIT_TIMEOUT) {
|
||||
TerminateThread(*phObserverThread, 0UL);
|
||||
assert("Observer Timeout Exceeded Error!" && false);
|
||||
}
|
||||
else {
|
||||
TerminateThread(*phObserverThread, 0UL);
|
||||
assert("Fatal Observer Error!" && false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
TerminateThread(*phObserverThread, 0UL);
|
||||
assert("Fatal: Invalid Observer Done Handle!" && false);
|
||||
}
|
||||
*phObserverThread = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
#pragma warning(pop)
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
void InstallFileWatching(const bool bInstall) {
|
||||
|
||||
static HANDLE _hChangeHandle = INVALID_HANDLE_VALUE; // observer
|
||||
@ -12639,40 +12672,13 @@ void InstallFileWatching(const bool bInstall) {
|
||||
|
||||
bool const bTerminate = !bInstall || !bWatchFile || !bFileDirExists;
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:6258)
|
||||
|
||||
// Terminate previous watching
|
||||
if (bTerminate) {
|
||||
|
||||
ResetFileObservationData(true);
|
||||
|
||||
KillTimer(Globals.hwndMain, ID_WATCHTIMER);
|
||||
|
||||
if (IS_VALID_HANDLE(_hObserverThread)) {
|
||||
if (IS_VALID_HANDLE(s_hEventObserverDone)) {
|
||||
DWORD const wait = SignalObjectAndWait(s_hEventObserverDone, _hObserverThread,
|
||||
/*INFINITE*/ (dwObservingTimeout << 1), FALSE);
|
||||
if (wait == WAIT_OBJECT_0) {
|
||||
CloseHandle(_hObserverThread); // ok
|
||||
}
|
||||
else if (wait == WAIT_TIMEOUT) {
|
||||
TerminateThread(_hObserverThread, 0UL);
|
||||
assert("Observer Timeout Exceeded Error!" && false);
|
||||
} else {
|
||||
TerminateThread(_hObserverThread, 0UL);
|
||||
assert("Fatal Observer Error!" && false);
|
||||
}
|
||||
} else {
|
||||
TerminateThread(_hObserverThread, 0UL);
|
||||
assert("Fatal: Invalid Observer Done Handle!" && false);
|
||||
}
|
||||
_hObserverThread = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
StopFileChangeObserver(&_hObserverThread);
|
||||
}
|
||||
|
||||
#pragma warning(pop)
|
||||
|
||||
if (bInstall) {
|
||||
|
||||
if (bWatchFile) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user