Skip to content

Commit

Permalink
Merge branch 'master' into Ignore_eof_newline_presence
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Dec 15, 2024
2 parents 455e747 + 39521d2 commit 6e50319
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 70 deletions.
19 changes: 4 additions & 15 deletions Externals/crystaledit/editlib/ccrystaltextview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,6 @@ using CrystalLineParser::TEXTBLOCK;
#endif


// The vcruntime.h version of _countf() gives syntax errors starting with VS 15.7.2,
// but only with `CCrystalTextView::m_SourceDefs` (which is local to this .cpp file),
// and only for X64 compilations (Win32 is ok, probably because no alignment issues
// are involved). I think that this could be related to C++17 compliance issues.
// This patch reverts to a 'traditional' definition of _countf(), a pre-existing
// part of the CCrystalTextView package.
#undef _countof
#ifndef _countof
#define _countof(array) (sizeof(array)/sizeof(array[0]))
#endif

#define DEFAULT_PRINT_MARGIN 1000 // 10 millimeters

#ifndef WM_MOUSEHWHEEL
Expand Down Expand Up @@ -325,7 +314,7 @@ DoSetTextType (CrystalLineParser::TextDefinition *def)
bool CCrystalTextView::
SetTextType (const tchar_t* pszExt)
{
m_CurSourceDef = CrystalLineParser::m_SourceDefs;
m_CurSourceDef = &CrystalLineParser::m_SourceDefs[0];

CrystalLineParser::TextDefinition *def = CrystalLineParser::GetTextType (pszExt);

Expand All @@ -337,8 +326,8 @@ SetTextType (CrystalLineParser::TextType enuType)
{
CrystalLineParser::TextDefinition *def;

m_CurSourceDef = def = CrystalLineParser::m_SourceDefs;
for (int i = 0; i < _countof (CrystalLineParser::m_SourceDefs); i++, def++)
m_CurSourceDef = def = &CrystalLineParser::m_SourceDefs[0];
for (size_t i = 0; i < CrystalLineParser::m_SourceDefs.size(); i++, def++)
{
if (def->type == enuType)
{
Expand Down Expand Up @@ -6307,7 +6296,7 @@ OnSourceType (UINT nId)
void CCrystalTextView::
OnUpdateSourceType (CCmdUI * pCmdUI)
{
pCmdUI->SetRadio (CrystalLineParser::m_SourceDefs + (pCmdUI->m_nID - ID_SOURCE_PLAIN) == m_CurSourceDef);
pCmdUI->SetRadio (&CrystalLineParser::m_SourceDefs[(pCmdUI->m_nID - ID_SOURCE_PLAIN)] == m_CurSourceDef);
}

int
Expand Down
121 changes: 71 additions & 50 deletions Externals/crystaledit/editlib/parsers/crystallineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,69 @@ namespace CrystalLineParser
// Tabsize is commented out since we have only GUI setting for it now.
// Not removed because we may later want to have per-filetype settings again.
// See ccrystaltextview.h for table declaration.
TextDefinition m_SourceDefs[] =
std::array<TextDefinition, SRC_MAX_ENTRY> m_SourceDefs =
{
SRC_PLAIN, _T ("Plain"), _T ("txt;doc;diz"), &ParseLinePlain, SRCOPT_AUTOINDENT, /*4,*/ _T (""), _T (""), _T (""), (unsigned)-1,
SRC_ABAP, _T("ABAP"), _T("abap"),& ParseLineAbap, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI , /*2,*/ _T(""), _T(""), _T("'"), (unsigned)-1,
SRC_ADA, _T ("Ada"), _T ("ads;adb"), &ParseLineAda, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*3,*/ _T (""), _T (""), _T ("'"), (unsigned)-1,
SRC_ASP, _T ("ASP"), _T ("asp;ascx"), &ParseLineAsp, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T (""), _T (""), _T ("'"), (unsigned)-1,
SRC_AUTOIT, _T ("AutoIt"), _T ("au3"), &ParseLineAutoIt, SRCOPT_AUTOINDENT, /*4,*/ _T (""), _T (""), _T (";"), (unsigned)-1,
SRC_BASIC, _T ("Basic"), _T ("bas;vb;vbs;frm;dsm;cls;ctl;pag;dsr"), &ParseLineBasic, SRCOPT_AUTOINDENT, /*4,*/ _T (""), _T (""), _T ("\'"), (unsigned)-1,
SRC_BATCH, _T ("Batch"), _T ("bat;btm;cmd"), &ParseLineBatch, SRCOPT_INSERTTABS|SRCOPT_AUTOINDENT, /*4,*/ _T (""), _T (""), _T ("rem "), (unsigned)-1,
SRC_C, _T ("C"), _T ("c;cc;cpp;cppm;ixx;cxx;h;hpp;hxx;hm;inl;rh;tlh;tli;xs"), &ParseLineC, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_CSHARP, _T ("C#"), _T ("cs"), &ParseLineCSharp, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_CSS, _T ("CSS"), _T ("css"), &ParseLineCss, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T (""), (unsigned)-1,
SRC_DCL, _T ("DCL"), _T ("dcl;dcc"), &ParseLineDcl, SRCOPT_AUTOINDENT|SRCOPT_BRACEGNU, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_DLANG, _T ("D"), _T ("d;di"), &ParseLineDlang, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_FORTRAN, _T ("Fortran"), _T ("f;f90;f9p;fpp;for;f77"), &ParseLineFortran, SRCOPT_INSERTTABS|SRCOPT_AUTOINDENT, /*8,*/ _T (""), _T (""), _T ("!"), (unsigned)-1,
SRC_FSHARP, _T ("F#"), _T ("fs;fsx"), &ParseLineFSharp, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_GO, _T ("Go"), _T ("go"), &ParseLineGo, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_HTML, _T ("HTML"), _T ("html;htm;shtml;ihtml;ssi;stm;stml;jsp"), &ParseLineHtml, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("<!--"), _T ("-->"), _T (""), (unsigned)-1,
SRC_INI, _T ("INI"), _T ("ini;reg;vbp;isl"), &ParseLineIni, SRCOPT_AUTOINDENT|SRCOPT_BRACEGNU|SRCOPT_EOLNUNIX, /*2,*/ _T (""), _T (""), _T (";"), (unsigned)-1,
SRC_INNOSETUP, _T ("InnoSetup"), _T ("iss"), &ParseLineInnoSetup, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("{"), _T ("}"), _T (";"), (unsigned)-1,
SRC_INSTALLSHIELD, _T ("InstallShield"), _T ("rul"), &ParseLineIS, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_JAVA, _T ("Java"), _T ("java;jav"), &ParseLineJava, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_JAVASCRIPT, _T ("JavaScript"), _T ("js;ts"), &ParseLineJavaScript, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_JSON, _T ("JSON"), _T ("json"), &ParseLineJavaScript, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_LISP, _T ("AutoLISP"), _T ("lsp;dsl"), &ParseLineLisp, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T (";|"), _T ("|;"), _T (";"), (unsigned)-1,
SRC_LUA, _T ("Lua"), _T ("lua"), &ParseLineLua, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("--[["), _T ("]]"), _T ("--"), (unsigned)-1,
SRC_MATLAB, _T ("MATLAB"), _T ("m"), &ParseLineMatlab, SRCOPT_AUTOINDENT | SRCOPT_BRACEANSI, /*2,*/ _T ("%{"), _T ("%}"), _T ("%"), (unsigned)-1,
SRC_NSIS, _T ("NSIS"), _T ("nsi;nsh"), &ParseLineNsis, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T (";"), (unsigned)-1,
SRC_PASCAL, _T ("Pascal"), _T ("pas"), &ParseLinePascal, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("{"), _T ("}"), _T (""), (unsigned)-1,
SRC_PERL, _T ("Perl"), _T ("pl;pm;plx"), &ParseLinePerl, SRCOPT_AUTOINDENT|SRCOPT_EOLNUNIX, /*4,*/ _T (""), _T (""), _T ("#"), (unsigned)-1,
SRC_PHP, _T ("PHP"), _T ("php;php3;php4;php5;phtml"), &ParseLinePhp, SRCOPT_AUTOINDENT|SRCOPT_BRACEGNU, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_PO, _T ("PO"), _T ("po;pot"), &ParseLinePo, SRCOPT_AUTOINDENT|SRCOPT_EOLNUNIX, /*4,*/ _T (""), _T (""), _T ("#"), (unsigned)-1,
SRC_POWERSHELL, _T ("PowerShell"), _T ("ps1"), &ParseLinePowerShell, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T (""), _T (""), _T ("#"), (unsigned)-1,
SRC_PYTHON, _T ("Python"), _T ("py"), &ParseLinePython, SRCOPT_AUTOINDENT|SRCOPT_BRACEGNU, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_REXX, _T ("REXX"), _T ("rex;rexx"), &ParseLineRexx, SRCOPT_AUTOINDENT, /*4,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_RSRC, _T ("Resources"), _T ("rc;dlg;r16;r32;rc2"), &ParseLineRsrc, SRCOPT_AUTOINDENT, /*4,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_RUBY, _T ("Ruby"), _T ("rb;rbw;rake;gemspec"), &ParseLineRuby, SRCOPT_AUTOINDENT|SRCOPT_EOLNUNIX, /*4,*/ _T (""), _T (""), _T ("#"), (unsigned)-1,
SRC_RUST, _T ("Rust"), _T ("rs"), &ParseLineRust, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_SGML, _T ("Sgml"), _T ("sgml"), &ParseLineSgml, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("<!--"), _T ("-->"), _T (""), (unsigned)-1,
SRC_SH, _T ("Shell"), _T ("sh;conf"), &ParseLineSh, SRCOPT_INSERTTABS|SRCOPT_AUTOINDENT|SRCOPT_EOLNUNIX, /*4,*/ _T (""), _T (""), _T ("#"), (unsigned)-1,
SRC_SIOD, _T ("SIOD"), _T ("scm"), &ParseLineSiod, SRCOPT_AUTOINDENT|SRCOPT_BRACEGNU, /*2,*/ _T (";|"), _T ("|;"), _T (";"), (unsigned)-1,
SRC_SMARTY, _T("Smarty"), _T("tpl"), &ParseLineSmarty, SRCOPT_AUTOINDENT | SRCOPT_BRACEGNU, /*2,*/ _T("{*"), _T("*}"), _T(""), (unsigned)-1,
SRC_SQL, _T ("SQL"), _T ("sql"), &ParseLineSql, SRCOPT_AUTOINDENT, /*4,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_TCL, _T ("TCL"), _T ("tcl"), &ParseLineTcl, SRCOPT_AUTOINDENT|SRCOPT_BRACEGNU|SRCOPT_EOLNUNIX, /*2,*/ _T (""), _T (""), _T ("#"), (unsigned)-1,
SRC_TEX, _T ("TEX"), _T ("tex;sty;clo;ltx;fd;dtx"), &ParseLineTex, SRCOPT_AUTOINDENT, /*4,*/ _T (""), _T (""), _T ("%"), (unsigned)-1,
SRC_VERILOG, _T ("Verilog"), _T ("v;vh"), &ParseLineVerilog, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_VHDL, _T ("VHDL"), _T ("vhd;vhdl;vho"), &ParseLineVhdl, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T (""), _T (""), _T ("--"), (unsigned)-1,
SRC_XML, _T ("XML"), _T ("xml"), &ParseLineXml, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("<!--"), _T ("-->"), _T (""), (unsigned)-1
SRC_PLAIN, _T ("Plain"), _T ("txt;doc;diz"), false, &ParseLinePlain, SRCOPT_AUTOINDENT, /*4,*/ _T (""), _T (""), _T (""), (unsigned)-1,
SRC_ABAP, _T("ABAP"), _T("abap"), false, & ParseLineAbap, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI , /*2,*/ _T(""), _T(""), _T("'"), (unsigned)-1,
SRC_ADA, _T ("Ada"), _T ("ads;adb"), false, &ParseLineAda, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*3,*/ _T (""), _T (""), _T ("'"), (unsigned)-1,
SRC_ASP, _T ("ASP"), _T ("asp;ascx"), false, &ParseLineAsp, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T (""), _T (""), _T ("'"), (unsigned)-1,
SRC_AUTOIT, _T ("AutoIt"), _T ("au3"), false, &ParseLineAutoIt, SRCOPT_AUTOINDENT, /*4,*/ _T (""), _T (""), _T (";"), (unsigned)-1,
SRC_BASIC, _T ("Basic"), _T ("bas;vb;vbs;frm;dsm;cls;ctl;pag;dsr"), false, &ParseLineBasic, SRCOPT_AUTOINDENT, /*4,*/ _T (""), _T (""), _T ("\'"), (unsigned)-1,
SRC_BATCH, _T ("Batch"), _T ("bat;btm;cmd"), false, &ParseLineBatch, SRCOPT_INSERTTABS|SRCOPT_AUTOINDENT, /*4,*/ _T (""), _T (""), _T ("rem "), (unsigned)-1,
SRC_C, _T ("C"), _T ("c;cc;cpp;cppm;ixx;cxx;h;hpp;hxx;hm;inl;rh;tlh;tli;xs"), false, &ParseLineC, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_CSHARP, _T ("C#"), _T ("cs"), false, &ParseLineCSharp, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_CSS, _T ("CSS"), _T ("css"), false, &ParseLineCss, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T (""), (unsigned)-1,
SRC_DCL, _T ("DCL"), _T ("dcl;dcc"), false, &ParseLineDcl, SRCOPT_AUTOINDENT|SRCOPT_BRACEGNU, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_DLANG, _T ("D"), _T ("d;di"), false, &ParseLineDlang, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_FORTRAN, _T ("Fortran"), _T ("f;f90;f9p;fpp;for;f77"), false, &ParseLineFortran, SRCOPT_INSERTTABS|SRCOPT_AUTOINDENT, /*8,*/ _T (""), _T (""), _T ("!"), (unsigned)-1,
SRC_FSHARP, _T ("F#"), _T ("fs;fsx"), false, &ParseLineFSharp, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_GO, _T ("Go"), _T ("go"), false, &ParseLineGo, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_HTML, _T ("HTML"), _T ("html;htm;shtml;ihtml;ssi;stm;stml;jsp"), false, &ParseLineHtml, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("<!--"), _T ("-->"), _T (""), (unsigned)-1,
SRC_INI, _T ("INI"), _T ("ini;reg;vbp;isl"), false, &ParseLineIni, SRCOPT_AUTOINDENT|SRCOPT_BRACEGNU|SRCOPT_EOLNUNIX, /*2,*/ _T (""), _T (""), _T (";"), (unsigned)-1,
SRC_INNOSETUP, _T ("InnoSetup"), _T ("iss"), false, &ParseLineInnoSetup, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("{"), _T ("}"), _T (";"), (unsigned)-1,
SRC_INSTALLSHIELD, _T ("InstallShield"), _T ("rul"), false, &ParseLineIS, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_JAVA, _T ("Java"), _T ("java;jav"), false, &ParseLineJava, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_JAVASCRIPT, _T ("JavaScript"), _T ("js;ts"), false, &ParseLineJavaScript, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_JSON, _T ("JSON"), _T ("json"), false, &ParseLineJavaScript, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_LISP, _T ("AutoLISP"), _T ("lsp;dsl"), false, &ParseLineLisp, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T (";|"), _T ("|;"), _T (";"), (unsigned)-1,
SRC_LUA, _T ("Lua"), _T ("lua"), false, &ParseLineLua, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("--[["), _T ("]]"), _T ("--"), (unsigned)-1,
SRC_MATLAB, _T ("MATLAB"), _T ("m"), false, &ParseLineMatlab, SRCOPT_AUTOINDENT | SRCOPT_BRACEANSI, /*2,*/ _T ("%{"), _T ("%}"), _T ("%"), (unsigned)-1,
SRC_NSIS, _T ("NSIS"), _T ("nsi;nsh"), false, &ParseLineNsis, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T (";"), (unsigned)-1,
SRC_PASCAL, _T ("Pascal"), _T ("pas"), false, &ParseLinePascal, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("{"), _T ("}"), _T (""), (unsigned)-1,
SRC_PERL, _T ("Perl"), _T ("pl;pm;plx"), false, &ParseLinePerl, SRCOPT_AUTOINDENT|SRCOPT_EOLNUNIX, /*4,*/ _T (""), _T (""), _T ("#"), (unsigned)-1,
SRC_PHP, _T ("PHP"), _T ("php;php3;php4;php5;phtml"), false, &ParseLinePhp, SRCOPT_AUTOINDENT|SRCOPT_BRACEGNU, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_PO, _T ("PO"), _T ("po;pot"), false, &ParseLinePo, SRCOPT_AUTOINDENT|SRCOPT_EOLNUNIX, /*4,*/ _T (""), _T (""), _T ("#"), (unsigned)-1,
SRC_POWERSHELL, _T ("PowerShell"), _T ("ps1"), false, &ParseLinePowerShell, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T (""), _T (""), _T ("#"), (unsigned)-1,
SRC_PYTHON, _T ("Python"), _T ("py"), false, &ParseLinePython, SRCOPT_AUTOINDENT|SRCOPT_BRACEGNU, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_REXX, _T ("REXX"), _T ("rex;rexx"), false, &ParseLineRexx, SRCOPT_AUTOINDENT, /*4,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_RSRC, _T ("Resources"), _T ("rc;dlg;r16;r32;rc2"), false, &ParseLineRsrc, SRCOPT_AUTOINDENT, /*4,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_RUBY, _T ("Ruby"), _T ("rb;rbw;rake;gemspec"), false, &ParseLineRuby, SRCOPT_AUTOINDENT|SRCOPT_EOLNUNIX, /*4,*/ _T (""), _T (""), _T ("#"), (unsigned)-1,
SRC_RUST, _T ("Rust"), _T ("rs"), false, &ParseLineRust, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_SGML, _T ("Sgml"), _T ("sgml"), false, &ParseLineSgml, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("<!--"), _T ("-->"), _T (""), (unsigned)-1,
SRC_SH, _T ("Shell"), _T ("sh;conf"), false, &ParseLineSh, SRCOPT_INSERTTABS|SRCOPT_AUTOINDENT|SRCOPT_EOLNUNIX, /*4,*/ _T (""), _T (""), _T ("#"), (unsigned)-1,
SRC_SIOD, _T ("SIOD"), _T ("scm"), false, &ParseLineSiod, SRCOPT_AUTOINDENT|SRCOPT_BRACEGNU, /*2,*/ _T (";|"), _T ("|;"), _T (";"), (unsigned)-1,
SRC_SMARTY, _T("Smarty"), _T("tpl"), false, &ParseLineSmarty, SRCOPT_AUTOINDENT | SRCOPT_BRACEGNU, /*2,*/ _T("{*"), _T("*}"), _T(""), (unsigned)-1,
SRC_SQL, _T ("SQL"), _T ("sql"), false, &ParseLineSql, SRCOPT_AUTOINDENT, /*4,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_TCL, _T ("TCL"), _T ("tcl"), false, &ParseLineTcl, SRCOPT_AUTOINDENT|SRCOPT_BRACEGNU|SRCOPT_EOLNUNIX, /*2,*/ _T (""), _T (""), _T ("#"), (unsigned)-1,
SRC_TEX, _T ("TEX"), _T ("tex;sty;clo;ltx;fd;dtx"), false, &ParseLineTex, SRCOPT_AUTOINDENT, /*4,*/ _T (""), _T (""), _T ("%"), (unsigned)-1,
SRC_VERILOG, _T ("Verilog"), _T ("v;vh"), false, &ParseLineVerilog, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("/*"), _T ("*/"), _T ("//"), (unsigned)-1,
SRC_VHDL, _T ("VHDL"), _T ("vhd;vhdl;vho"), false, &ParseLineVhdl, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T (""), _T (""), _T ("--"), (unsigned)-1,
SRC_XML, _T ("XML"), _T ("xml"), false, &ParseLineXml, SRCOPT_AUTOINDENT|SRCOPT_BRACEANSI, /*2,*/ _T ("<!--"), _T ("-->"), _T (""), (unsigned)-1
};

class SourceDefs
{
public:
~SourceDefs()
{
for (auto def : m_SourceDefs)
{
if (def.extsIsDynamic)
delete[] def.exts;
}
}
} m_sourceDefs;

static bool
MatchType (const std::basic_string<tchar_t>& pattern, const tchar_t* lpszExt)
{
Expand Down Expand Up @@ -98,12 +111,12 @@ GetTextType (const tchar_t *pszExt)

def = &m_SourceDefs[1];
std::transform(sExt.begin(), sExt.end(), sExt.begin(), tc::totlower);
for (int i = 1; i < _countof (m_SourceDefs); i++, def++)
for (size_t i = 1; i < m_SourceDefs.size(); i++, def++)
if (MatchType (def->exts, sExt.c_str()))
return def;

// Check if the extension matches the text type "Plain" at the end.
def = m_SourceDefs;
def = &m_SourceDefs[0];
if (MatchType (def->exts, sExt.c_str()))
return def;

Expand Down Expand Up @@ -134,7 +147,15 @@ SetExtension(int index, const tchar_t *pszExts)
if (index < 0 || index > SRC_XML)
return;

tc::tcslcpy(m_SourceDefs[index].exts, pszExts);
auto& def = m_SourceDefs[index];
if (tc::tcscmp(def.exts, pszExts) == 0)
return;
if (def.extsIsDynamic)
delete[] def.exts;
const size_t size = tc::tcslen(pszExts) + 1;
def.exts = new tchar_t[size];
tc::tcslcpy(def.exts, size, pszExts);
def.extsIsDynamic = true;
}

}
7 changes: 4 additions & 3 deletions Externals/crystaledit/editlib/parsers/crystallineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ TextType;
struct TextDefinition
{
TextType type;
tchar_t name[256];
tchar_t exts[256];
const tchar_t* name;
tchar_t* exts;
bool extsIsDynamic;
unsigned (* ParseLineX) (unsigned dwCookie, const tchar_t *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);
unsigned flags;
// unsigned tabsize;
Expand All @@ -143,7 +144,7 @@ struct TextDefinition
unsigned encoding;
};

extern TextDefinition m_SourceDefs[SRC_MAX_ENTRY];
extern std::array<TextDefinition, SRC_MAX_ENTRY> m_SourceDefs;

bool IsXKeyword(const tchar_t *pszKey, size_t nKeyLen, const tchar_t *pszKeywordList[], size_t nKeywordListCount, int(*compare)(const tchar_t *, const tchar_t *, size_t));
bool IsXNumber(const tchar_t* pszChars, int nLength);
Expand Down
2 changes: 0 additions & 2 deletions Src/PropEditorSyntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ void PropEditorSyntax::InitList()
m_listSyntax.SetReadOnlyColumn(0);
m_listSyntax.SetEditStyle(1, CSubeditList::EditStyle::WILDCARD_DROP_LIST);

int nLimitTextSize = (sizeof(CrystalLineParser::TextDefinition::exts) / sizeof(CrystalLineParser::TextDefinition::exts[0])) - 1;
m_listSyntax.SetLimitTextSize(1, nLimitTextSize);

String fixedPattern[CrystalLineParser::SRC_XML];
Options::EditorSyntax::GetDefaults(GetOptionsMgr(), fixedPattern);
Expand Down

0 comments on commit 6e50319

Please sign in to comment.