Skip to content

Commit d95e354

Browse files
committed
Fixed problem with triggers if you changed to/from UTF-8 mode
1 parent 545d2fd commit d95e354

File tree

2 files changed

+119
-2
lines changed

2 files changed

+119
-2
lines changed

dialogs/world_prefs/configuration.cpp

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,9 @@ void CMUSHclientDoc:: SavePrefsP13 (CPrefsP13 &page13)
15441544
void CMUSHclientDoc:: SavePrefsP14 (CPrefsP14 &page14)
15451545
{
15461546
DelayDebugMsg ("Saving", 14);
1547+
1548+
bool utf8Changed = m_bUTF_8 != page14.m_bUTF_8;
1549+
15471550
m_font_height = page14.m_font_height;
15481551
m_font_name = page14.m_font_name;
15491552
m_font_weight = page14.m_font_weight;
@@ -1618,6 +1621,25 @@ void CMUSHclientDoc:: SavePrefsP14 (CPrefsP14 &page14)
16181621

16191622
FixInputWrap();
16201623

1624+
// changing to or from UTF-8 will alter the way trigger and alias regular expressions
1625+
// need to be compiled so we recompile all of them
1626+
if (utf8Changed)
1627+
{
1628+
m_CurrentPlugin = NULL;
1629+
RecompileRegularExpressions (); // do main world
1630+
1631+
// do plugins
1632+
for (PluginListIterator pit = m_PluginList.begin ();
1633+
pit != m_PluginList.end ();
1634+
++pit)
1635+
{
1636+
m_CurrentPlugin = *pit;
1637+
RecompileRegularExpressions (); // do this plugin
1638+
} // end of doing each plugin
1639+
1640+
m_CurrentPlugin = NULL; // not in a plugin any more
1641+
} // end of utf8Changed
1642+
16211643
} // end of CMUSHclientDoc::SavePrefsP14
16221644

16231645
void CMUSHclientDoc:: SavePrefsP15 (CPrefsP15 &page15)
@@ -2351,10 +2373,103 @@ Frame.DelayDebugStatus ("World config - loading pages");
23512373
Frame.SetStatusNormal ();
23522374

23532375
return true; // did it OK
2354-
}
2376+
} // end of CMUSHclientDoc::GamePreferences
23552377

23562378

23572379
void CMUSHclientDoc::OnGamePreferences()
23582380
{
23592381
GamePreferences (-1); // use last page, whatever it was
2360-
}
2382+
} // end of CMUSHclientDoc::OnGamePreferences
2383+
2384+
void CMUSHclientDoc::RecompileRegularExpressions ()
2385+
{
2386+
int iTriggerErrors = 0;
2387+
#if ALIASES_USE_UTF8
2388+
int iAliasErrors = 0;
2389+
#endif // ALIASES_USE_UTF8
2390+
2391+
POSITION pos;
2392+
CString strName;
2393+
CString strRegexp;
2394+
2395+
for (pos = GetTriggerMap ().GetStartPosition(); pos;)
2396+
{
2397+
CTrigger * pTrigger;
2398+
GetTriggerMap ().GetNextAssoc (pos, strName, pTrigger);
2399+
2400+
if (pTrigger->regexp)
2401+
{
2402+
delete pTrigger->regexp; // get rid of old one
2403+
if (pTrigger->bRegexp)
2404+
strRegexp = pTrigger->trigger;
2405+
else
2406+
strRegexp = ConvertToRegularExpression (pTrigger->trigger);
2407+
}
2408+
2409+
// compile regular expression
2410+
try
2411+
{
2412+
pTrigger->regexp = regcomp (strRegexp, (pTrigger->ignore_case ? PCRE_CASELESS : 0) |
2413+
(pTrigger->bMultiLine ? PCRE_MULTILINE : 0) |
2414+
(m_bUTF_8 ? PCRE_UTF8 : 0)
2415+
);
2416+
} // end of try
2417+
catch(CException* e)
2418+
{
2419+
e->Delete ();
2420+
iTriggerErrors++;
2421+
pTrigger->regexp = NULL;
2422+
} // end of catch
2423+
} // end of for each trigger
2424+
2425+
#if ALIASES_USE_UTF8
2426+
2427+
for (pos = GetAliasMap ().GetStartPosition(); pos;)
2428+
{
2429+
CAlias * pAlias;
2430+
GetAliasMap ().GetNextAssoc (pos, strName, pAlias);
2431+
2432+
if (pAlias->regexp)
2433+
{
2434+
delete pAlias->regexp; // get rid of old one
2435+
if (pAlias->bRegexp)
2436+
strRegexp = pAlias->name;
2437+
else
2438+
strRegexp = ConvertToRegularExpression (pAlias->name);
2439+
}
2440+
2441+
// compile regular expression
2442+
try
2443+
{
2444+
pAlias->regexp = regcomp (strRegexp, (pAlias->bIgnoreCase ? PCRE_CASELESS : 0) |
2445+
(m_bUTF_8 ? PCRE_UTF8 : 0)
2446+
);
2447+
} // end of try
2448+
catch(CException* e)
2449+
{
2450+
e->Delete ();
2451+
iAliasErrors++;
2452+
pAlias->regexp = NULL;
2453+
} // end of catch
2454+
} // end of for each alias
2455+
2456+
#endif // ALIASES_USE_UTF8
2457+
2458+
const char * sPluginName = "(Main world)";
2459+
2460+
if (m_CurrentPlugin)
2461+
sPluginName = m_CurrentPlugin->m_strName;
2462+
2463+
if (iTriggerErrors)
2464+
ColourNote ("white", "red",
2465+
TFormat ("In plugin %s, %i trigger(s) could not be recompiled.",
2466+
sPluginName, iTriggerErrors));
2467+
2468+
#if ALIASES_USE_UTF8
2469+
if (iAliasErrors)
2470+
ColourNote ("white", "red",
2471+
TFormat ("In plugin %s, %i alias(es) could not be recompiled.",
2472+
sPluginName, iAliasErrors));
2473+
#endif // ALIASES_USE_UTF8
2474+
2475+
} // end of CMUSHclientDoc::RecompileRegularExpressions

doc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,8 @@ class CMUSHclientDoc : public CDocument
21472147
void DebugShow (const char * sTitle, const CTime theDate);
21482148
void DebugShowD (const char * sTitle, const double fNumber);
21492149

2150+
// in case we switch to/from UTF-8 mode
2151+
void RecompileRegularExpressions ();
21502152

21512153
// helper routines to get the appropriate map
21522154
CTriggerMap & GetTriggerMap (void)

0 commit comments

Comments
 (0)