Skip to content

Commit 263742e

Browse files
committed
default rules for "makefile" (no file extension)
1 parent ef802a9 commit 263742e

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

MBlockEditor/src/BlockEditor.cpp

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838

3939
#include "../../common/plugin.h"
4040

41+
#include <algorithm>
42+
using namespace std; //FIXME: bad practice. https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
4143

4244
#ifdef MDEBUG
4345
//#include "/VCProject/MLib/MLibDef.h"
@@ -849,50 +851,82 @@ BOOL DoTabLeft()
849851
return TRUE;
850852
}
851853

852-
void SetCommentDefaults(LPCTSTR psExt)
854+
bool filename_match(LPCTSTR fn, LPCTSTR ref)
853855
{
854-
if (_tcsicmp(psExt, _T(".bat"))==0 || _tcsicmp(psExt, _T(".cmd"))==0)
856+
LPCTSTR _fn = & fn[ lstrlen(fn)-lstrlen(ref) ];
857+
return (_tcsicmp(_fn, ref) == 0);
858+
}
859+
860+
//match string to one from to comma separated list
861+
bool _ext_match_to_any(LPCTSTR str, LPCTSTR clst)
862+
{
863+
int slen = lstrlen(str);
864+
int clen = lstrlen(clst);
865+
for (int idx=0, i=0; i<clen;)
866+
{
867+
idx = (str[idx] == clst[i++]) ? idx+1 : 0;
868+
if ( (idx == slen) && ((i == clen) || clst[i] == _T(',')) )
869+
{
870+
return true;
871+
}
872+
}
873+
return false;
874+
}
875+
876+
void SetCommentDefaults(LPCTSTR pszFileName, LPCTSTR psExt)
877+
{
878+
if ( filename_match(pszFileName, _T("makefile")) )
879+
{
880+
psComment = _T("#");
881+
lbSkipNonSpace = FALSE;
882+
lbSkipCommentMenu = TRUE;
883+
return;
884+
}
885+
886+
if (psExt == NULL) return;
887+
888+
#define EXT_MATCH(x) _ext_match_to_any(psExt, _T(x))
889+
if ( EXT_MATCH("bat,cmd") )
855890
{
856891
psComment = _T("rem \0REM \0");
857892
lbSkipNonSpace = FALSE;
858893
lbSkipCommentMenu = TRUE;
859894
}
860-
else if (_tcsicmp(psExt, _T(".sql"))==0)
895+
else if ( EXT_MATCH("sql") )
861896
{
862897
psComment = _T("--");
863898
psCommentBegin = _T("/*");
864899
psCommentEnd = _T("*/");
865900
lbSkipNonSpace = FALSE;
866901
}
867-
else if (_tcsicmp(psExt, _T(".bas"))==0 || _tcsicmp(psExt, _T(".vbs"))==0)
902+
else if ( EXT_MATCH("bas,vbs") )
868903
{
869904
psComment = _T("'");
870905
}
871-
else if (_tcsicmp(psExt, _T(".cpp"))==0 || _tcsicmp(psExt, _T(".c"))==0 || _tcsicmp(psExt, _T(".cxx"))==0 ||
872-
_tcsicmp(psExt, _T(".hpp"))==0 || _tcsicmp(psExt, _T(".h"))==0 || _tcsicmp(psExt, _T(".hxx"))==0)
906+
else if ( EXT_MATCH("cpp,c,cxx,hpp,h,hxx") )
873907
{
874908
psCommentBegin = _T("/*");
875-
psCommentEnd = _T("*/");
909+
psCommentEnd = _T("*/");
876910
}
877-
else if (_tcsicmp(psExt, _T(".htm"))==0 || _tcsicmp(psExt, _T(".html"))==0 || _tcsicmp(psExt, _T(".xml"))==0)
911+
else if ( EXT_MATCH("htm,html,xml") )
878912
{
879913
psCommentBegin = _T("<!--");
880914
psCommentEnd = _T("-->");
881915
psComment = _T("");
882916
}
883-
else if (_tcsicmp(psExt, _T(".php"))==0)
917+
else if ( EXT_MATCH("php") )
884918
{
885919
psCommentBegin = _T("<!--\0/*\0");
886920
psCommentEnd = _T("-->\0*/\0");
887921
psComment = _T("//\0#\0");
888922
}
889-
else if (_tcsicmp(psExt, _T(".ps1"))==0 || _tcsicmp(psExt, _T(".psm1"))==0)
923+
else if ( EXT_MATCH("ps1,psm1") )
890924
{
891925
psCommentBegin = _T("<#");
892926
psCommentEnd = _T("#>");
893927
psComment = _T("#");
894928
}
895-
else if (_tcsicmp(psExt, _T(".lua"))==0 || _tcsicmp(psExt, _T(".psm1"))==0)
929+
else if ( EXT_MATCH("lua,psm1") )
896930
{
897931
psComment = _T("--");
898932
}
@@ -991,9 +1025,7 @@ void LoadCommentSettings(LPCTSTR pszFileName, TCHAR (&szComment)[100], TCHAR (&s
9911025
}
9921026
}
9931027

994-
// Если НЕ NULL - значит в настройках плагина ничего прописано не было
995-
if (psExt)
996-
SetCommentDefaults(psExt);
1028+
SetCommentDefaults(pszFileName, psExt);
9971029
}
9981030

9991031
BOOL DoComment()

MBlockEditor/src/MBlockEditor.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,8 @@
11341134
<WarningLevel>Level3</WarningLevel>
11351135
<SuppressStartupBanner>true</SuppressStartupBanner>
11361136
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
1137+
<OmitFramePointers>true</OmitFramePointers>
1138+
<WholeProgramOptimization>true</WholeProgramOptimization>
11371139
</ClCompile>
11381140
<ResourceCompile>
11391141
<PreprocessorDefinitions>_DEBUG;FAR_UNICODE=3000;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -1153,6 +1155,7 @@
11531155
<TargetMachine>MachineX64</TargetMachine>
11541156
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
11551157
<SubSystem>Windows</SubSystem>
1158+
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
11561159
</Link>
11571160
<Bscmake>
11581161
<SuppressStartupBanner>true</SuppressStartupBanner>

0 commit comments

Comments
 (0)