Skip to content

Commit

Permalink
default rules for "makefile" (no file extension)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimstik committed Dec 10, 2020
1 parent ef802a9 commit 263742e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
60 changes: 46 additions & 14 deletions MBlockEditor/src/BlockEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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

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

#ifdef MDEBUG
//#include "/VCProject/MLib/MLibDef.h"
Expand Down Expand Up @@ -849,50 +851,82 @@ BOOL DoTabLeft()
return TRUE;
}

void SetCommentDefaults(LPCTSTR psExt)
bool filename_match(LPCTSTR fn, LPCTSTR ref)
{
if (_tcsicmp(psExt, _T(".bat"))==0 || _tcsicmp(psExt, _T(".cmd"))==0)
LPCTSTR _fn = & fn[ lstrlen(fn)-lstrlen(ref) ];
return (_tcsicmp(_fn, ref) == 0);
}

//match string to one from to comma separated list
bool _ext_match_to_any(LPCTSTR str, LPCTSTR clst)
{
int slen = lstrlen(str);
int clen = lstrlen(clst);
for (int idx=0, i=0; i<clen;)
{
idx = (str[idx] == clst[i++]) ? idx+1 : 0;
if ( (idx == slen) && ((i == clen) || clst[i] == _T(',')) )
{
return true;
}
}
return false;
}

void SetCommentDefaults(LPCTSTR pszFileName, LPCTSTR psExt)
{
if ( filename_match(pszFileName, _T("makefile")) )
{
psComment = _T("#");
lbSkipNonSpace = FALSE;
lbSkipCommentMenu = TRUE;
return;
}

if (psExt == NULL) return;

#define EXT_MATCH(x) _ext_match_to_any(psExt, _T(x))
if ( EXT_MATCH("bat,cmd") )
{
psComment = _T("rem \0REM \0");
lbSkipNonSpace = FALSE;
lbSkipCommentMenu = TRUE;
}
else if (_tcsicmp(psExt, _T(".sql"))==0)
else if ( EXT_MATCH("sql") )
{
psComment = _T("--");
psCommentBegin = _T("/*");
psCommentEnd = _T("*/");
lbSkipNonSpace = FALSE;
}
else if (_tcsicmp(psExt, _T(".bas"))==0 || _tcsicmp(psExt, _T(".vbs"))==0)
else if ( EXT_MATCH("bas,vbs") )
{
psComment = _T("'");
}
else if (_tcsicmp(psExt, _T(".cpp"))==0 || _tcsicmp(psExt, _T(".c"))==0 || _tcsicmp(psExt, _T(".cxx"))==0 ||
_tcsicmp(psExt, _T(".hpp"))==0 || _tcsicmp(psExt, _T(".h"))==0 || _tcsicmp(psExt, _T(".hxx"))==0)
else if ( EXT_MATCH("cpp,c,cxx,hpp,h,hxx") )
{
psCommentBegin = _T("/*");
psCommentEnd = _T("*/");
psCommentEnd = _T("*/");
}
else if (_tcsicmp(psExt, _T(".htm"))==0 || _tcsicmp(psExt, _T(".html"))==0 || _tcsicmp(psExt, _T(".xml"))==0)
else if ( EXT_MATCH("htm,html,xml") )
{
psCommentBegin = _T("<!--");
psCommentEnd = _T("-->");
psComment = _T("");
}
else if (_tcsicmp(psExt, _T(".php"))==0)
else if ( EXT_MATCH("php") )
{
psCommentBegin = _T("<!--\0/*\0");
psCommentEnd = _T("-->\0*/\0");
psComment = _T("//\0#\0");
}
else if (_tcsicmp(psExt, _T(".ps1"))==0 || _tcsicmp(psExt, _T(".psm1"))==0)
else if ( EXT_MATCH("ps1,psm1") )
{
psCommentBegin = _T("<#");
psCommentEnd = _T("#>");
psComment = _T("#");
}
else if (_tcsicmp(psExt, _T(".lua"))==0 || _tcsicmp(psExt, _T(".psm1"))==0)
else if ( EXT_MATCH("lua,psm1") )
{
psComment = _T("--");
}
Expand Down Expand Up @@ -991,9 +1025,7 @@ void LoadCommentSettings(LPCTSTR pszFileName, TCHAR (&szComment)[100], TCHAR (&s
}
}

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

BOOL DoComment()
Expand Down
3 changes: 3 additions & 0 deletions MBlockEditor/src/MBlockEditor.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,8 @@
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<OmitFramePointers>true</OmitFramePointers>
<WholeProgramOptimization>true</WholeProgramOptimization>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;FAR_UNICODE=3000;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand All @@ -1153,6 +1155,7 @@
<TargetMachine>MachineX64</TargetMachine>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<SubSystem>Windows</SubSystem>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
Expand Down

0 comments on commit 263742e

Please sign in to comment.