Skip to content

Instantly share code, notes, and snippets.

@leha-bot
Created February 26, 2019 18:00
Show Gist options
  • Save leha-bot/8e7bf3ed42e88d92b7bad167f3e3d7a7 to your computer and use it in GitHub Desktop.
Save leha-bot/8e7bf3ed42e88d92b7bad167f3e3d7a7 to your computer and use it in GitHub Desktop.
SYNTAXFILE* StackLoadSyntaxFile(STACKSYNTAXFILE *hStack, SYNTAXFILE *lpSyntaxFile)
{
HANDLE hFile;
DELIMITERINFO *lpDelimElement=NULL;
WORDINFO *lpWordElement=NULL;
QUOTEINFO *lpQuoteElement=NULL;
WILDCARDINFO *lpWildElement=NULL;
FOLDINFO *lpFoldInfo=NULL;
SKIPINFO *lpSkipInfo=NULL;
STACKVAR *lpVarStack;
wchar_t wszFile[MAX_PATH];
const wchar_t *wpFileName;
wchar_t *wszText;
const wchar_t *wpText;
const wchar_t *wpTextStart;
const wchar_t *wpSectionStart;
const wchar_t *wpLineStart;
wchar_t *wpWildcard;
wchar_t *wpDelimiter;
wchar_t *wpWord;
wchar_t *wpQuoteStart;
wchar_t *wpQuoteEnd;
wchar_t *wpQuoteInclude;
wchar_t *wpQuoteExclude;
wchar_t *wpSkipStart;
wchar_t *wpSkipEnd;
wchar_t *wpFoldStart;
wchar_t *wpFoldEnd;
wchar_t *wpFoldDelimiters;
wchar_t *wpRuleFile;
wchar_t wchEscape;
DWORD dwFileSize;
DWORD dwBytesRead;
DWORD dwUnicodeLen;
int nWildcardLen;
int nDelimiterLen;
int nWordLen;
int nQuoteStartLen;
int nQuoteEndLen;
int nQuoteIncludeLen;
int nQuoteExcludeLen;
int nSkipStartLen;
int nSkipEndLen;
int nFoldStartLen;
int nFoldEndLen;
int nDelimitersLen;
int nRuleLen;
int nBlockLen;
int nBlockParsedLen;
int nLinesInBlock;
INT_PTR nExpandLen;
DWORD dwFlags;
DWORD dwFontStyle;
DWORD dwColor1;
DWORD dwColor2;
int nParentID;
int nRuleID;
BOOL bQuoteString;
BOOL bExactTitle;
xprintfW(wszFile, L"%s\\%s", wszCoderDir, lpSyntaxFile->wszSyntaxFileName);
if ((hFile=CreateFileWide(wszFile, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN, NULL)) == INVALID_HANDLE_VALUE)
return NULL;
if ((dwFileSize=GetFileSize(hFile, NULL)) != INVALID_FILE_SIZE)
{
xmemset(&lpSyntaxFile->ftTimeStamp, 0, sizeof(FILETIME));
GetFileTime(hFile, NULL, NULL, &lpSyntaxFile->ftTimeStamp);
if (dwFileSize >= 2)
{
if (wszText=(wchar_t *)GlobalAlloc(GPTR, dwFileSize + 2))
{
if (ReadFile(hFile, wszText, dwFileSize, &dwBytesRead, NULL))
{
wpText=(const wchar_t *)wszText;
dwUnicodeLen=dwBytesRead / sizeof(wchar_t);
wszText[dwUnicodeLen++]=L'\0';
if (wszText[0] == 0xFEFF)
{
++wpText;
--dwUnicodeLen;
}
wpTextStart=wpText;
lpLoadSyntaxFile=lpSyntaxFile;
bSyntaxFileLoadError=FALSE;
//Set variable theme associated with syntax file
wpFileName=GetFileName(wszFile, -1);
if (!lpSyntaxFile->lpVarThemeLink)
lpVarStack=&lpVarThemeActive->hVarStack;
else
lpVarStack=&lpSyntaxFile->lpVarThemeLink->hVarStack;
if (lpSyntaxFile)
{
SectionStart:
if (!SkipComment(&wpText)) goto FreeText;
if (*wpText == L'\r' || *wpText == L'\n')
{
do
{
++wpText;
}
while (*wpText == L'\r' || *wpText == L'\n');
goto SectionStart;
}
wpSectionStart=wpText;
GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack);
if (!NextLine(&wpText)) goto FreeText;
if (!SkipComment(&wpText)) goto FreeText;
if (bSyntaxFileLoadError) goto FreeText;
if (!xstrcmpiW(wszBuffer, L"Files:"))
{
for (;;)
{
//Parse line
lpWildElement=NULL;
wpWildcard=NULL;
for (;;)
{
//Wildcard
if ((nWildcardLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack)) || bQuoteString)
{
if (!bQuoteString && wszBuffer[0] == L';') break;
if (lpSyntaxFile->bReserveCacheWildcard) break;
if (wpWildcard=(wchar_t *)GlobalAlloc(GPTR, (nWildcardLen + 1) * sizeof(wchar_t)))
xmemcpy(wpWildcard, wszBuffer, (nWildcardLen + 1) * sizeof(wchar_t));
else
break;
}
else goto SectionStart;
//Add to stack
if (lpWildElement=StackInsertWildcard(&lpSyntaxFile->hWildcardStack, nWildcardLen))
{
lpWildElement->wpWildcard=wpWildcard;
lpWildElement->nWildcardLen=nWildcardLen;
}
break;
}
if (!lpWildElement && wpWildcard) GlobalFree((HGLOBAL)wpWildcard);
if (!NextLine(&wpText)) goto FreeText;
if (bSyntaxFileLoadError) goto FreeText;
}
}
//HighLight
else if (!xstrcmpiW(wszBuffer, L"Delimiters:"))
{
for (;;)
{
//Parse line
lpDelimElement=NULL;
wpDelimiter=NULL;
dwFlags=AEHLF_MATCHCASE;
dwFontStyle=0;
dwColor1=(DWORD)-1;
dwColor2=(DWORD)-1;
nParentID=0;
for (;;)
{
//Highlight flags
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
dwFlags=(DWORD)xatoiW(wszBuffer, NULL);
if (dwFlags == 0 && wszBuffer[0] != L'0') break;
}
else goto SectionStart;
//Font style
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
dwFontStyle=(DWORD)xatoiW(wszBuffer, NULL);
}
else break;
//Color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
dwColor1=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
else break;
//Background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
dwColor2=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
else break;
//Delimiter
if (nDelimiterLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (wpDelimiter=(wchar_t *)GlobalAlloc(GPTR, (nDelimiterLen + 1) * sizeof(wchar_t)))
xmemcpy(wpDelimiter, wszBuffer, (nDelimiterLen + 1) * sizeof(wchar_t));
else
break;
}
else break;
//Parent ID
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
nParentID=(int)xatoiW(wszBuffer, NULL);
}
//Add to stack
if (lpDelimElement=StackInsertDelimiter(&lpSyntaxFile->hDelimiterStack, nDelimiterLen))
{
lpDelimElement->wpDelimiter=wpDelimiter;
lpDelimElement->nDelimiterLen=nDelimiterLen;
lpDelimElement->dwFlags=dwFlags;
lpDelimElement->dwFontStyle=dwFontStyle;
lpDelimElement->dwColor1=dwColor1;
lpDelimElement->dwColor2=dwColor2;
lpDelimElement->nParentID=nParentID;
}
break;
}
if (!lpDelimElement && wpDelimiter) GlobalFree((HGLOBAL)wpDelimiter);
if (!NextLine(&wpText)) goto FreeText;
if (bSyntaxFileLoadError) goto FreeText;
}
}
else if (!xstrcmpiW(wszBuffer, L"Font:"))
{
//Parse line
for (;;)
{
HDC hDC;
int nFontPointSize=0;
lpSyntaxFile->dwFontFlags=0;
lpSyntaxFile->lfFont.lfHeight=0;
lpSyntaxFile->lfFont.lfWidth=0;
lpSyntaxFile->lfFont.lfEscapement=0;
lpSyntaxFile->lfFont.lfOrientation=0;
lpSyntaxFile->lfFont.lfWeight=0;
lpSyntaxFile->lfFont.lfItalic=FALSE;
lpSyntaxFile->lfFont.lfUnderline=FALSE;
lpSyntaxFile->lfFont.lfStrikeOut=FALSE;
lpSyntaxFile->lfFont.lfCharSet=DEFAULT_CHARSET;
lpSyntaxFile->lfFont.lfOutPrecision=OUT_DEFAULT_PRECIS;
lpSyntaxFile->lfFont.lfClipPrecision=CLIP_DEFAULT_PRECIS;
lpSyntaxFile->lfFont.lfQuality=DEFAULT_QUALITY;
lpSyntaxFile->lfFont.lfPitchAndFamily=DEFAULT_PITCH;
lpSyntaxFile->lfFont.lfFaceName[0]=L'\0';
//Font style
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
dwFontStyle=(DWORD)xatoiW(wszBuffer, NULL);
if (dwFontStyle)
{
lpSyntaxFile->dwFontFlags|=FF_FONTSTYLE;
lpSyntaxFile->lfFont.lfWeight=(dwFontStyle == AEHLS_FONTBOLD || dwFontStyle == AEHLS_FONTBOLDITALIC)?FW_BOLD:FW_NORMAL;
lpSyntaxFile->lfFont.lfItalic=(dwFontStyle == AEHLS_FONTITALIC || dwFontStyle == AEHLS_FONTBOLDITALIC)?TRUE:FALSE;
}
else if (wszBuffer[0] != L'0') break;
}
//Font size
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
nFontPointSize=(int)xatoiW(wszBuffer, NULL);
if (nFontPointSize)
{
if (hDC=GetDC(hMainWnd))
{
lpSyntaxFile->dwFontFlags|=FF_FONTSIZE;
lpSyntaxFile->lfFont.lfHeight=-MulDiv(nFontPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
ReleaseDC(hMainWnd, hDC);
}
}
else if (wszBuffer[0] != L'0') break;
}
//Face name
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
lpSyntaxFile->dwFontFlags|=FF_FONTFACE;
xstrcpynW(lpSyntaxFile->lfFont.lfFaceName, wszBuffer, LF_FACESIZE);
}
break;
}
}
else if (!xstrcmpiW(wszBuffer, L"Colors:"))
{
//Parse line
for (;;)
{
lpSyntaxFile->aecColors.dwFlags=0;
//Basic text color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crBasicText=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_BASICTEXT;
}
else if (*wszBuffer != L'0') break;
}
//Basic bkgrnd color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crBasicBk=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_BASICBK;
}
else if (*wszBuffer != L'0') break;
}
//Sel text color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crSelText=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_SELTEXT;
}
else if (*wszBuffer != L'0') break;
}
//Sel bkgrnd color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crSelBk=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_SELBK;
}
else if (*wszBuffer != L'0') break;
}
//Line text color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crActiveLineText=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_ACTIVELINETEXT;
}
else if (*wszBuffer != L'0') break;
}
//Line bkgrnd color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crActiveLineBk=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_ACTIVELINEBK;
}
else if (*wszBuffer != L'0') break;
}
//Line border color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crActiveLineBorder=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_ACTIVELINEBORDER;
}
else if (*wszBuffer != L'0') break;
}
//Alt line text color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crAltLineText=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_ALTLINETEXT;
}
else if (*wszBuffer != L'0') break;
}
//Alt line bkgrnd color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crAltLineBk=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_ALTLINEBK;
}
else if (*wszBuffer != L'0') break;
}
//Alt border color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crAltLineBorder=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_ALTLINEBORDER;
}
else if (*wszBuffer != L'0') break;
}
//Column color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crActiveColumn=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_ACTIVECOLUMN;
}
else if (*wszBuffer != L'0') break;
}
//Marker color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crColumnMarker=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_COLUMNMARKER;
}
else if (*wszBuffer != L'0') break;
}
//Caret color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crCaret=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_CARET;
}
else if (*wszBuffer != L'0') break;
}
//URL color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crUrlText=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_URLTEXT;
}
else if (*wszBuffer != L'0') break;
}
//Active URL color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crUrlCursorText=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_URLCURSORTEXT;
}
else if (*wszBuffer != L'0') break;
}
//Visit URL color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->aecColors.crUrlVisitText=GetColorFromStr(wszBuffer + 1, NULL);
lpSyntaxFile->aecColors.dwFlags|=AECLR_URLVISITTEXT;
}
else if (*wszBuffer != L'0') break;
}
break;
}
}
else if (!xstrcmpiW(wszBuffer, L"BkImage:"))
{
//Parse line
for (;;)
{
//BkImage file
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
xstrcpynW(lpSyntaxFile->wszBkImageFile, wszBuffer, BUFFER_SIZE);
}
//BkImage alpha transparency
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
lpSyntaxFile->nBkImageAlpha=(DWORD)xatoiW(wszBuffer, NULL);
}
break;
}
}
else if (!xstrcmpiW(wszBuffer, L"AutoMark:"))
{
//Parse line
for (;;)
{
lpSyntaxFile->dwAutoMarkFlags=AEHLF_MATCHCASE;
lpSyntaxFile->dwAutoMarkFontStyle=AEHLS_NONE;
lpSyntaxFile->dwAutoMarkTextColor=(DWORD)-1;
lpSyntaxFile->dwAutoMarkBkColor=(DWORD)-1;
//AutoMark flags
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
lpSyntaxFile->dwAutoMarkFlags=(DWORD)xatoiW(wszBuffer, NULL);
if (lpSyntaxFile->dwAutoMarkFlags == 0 && wszBuffer[0] != L'0') break;
}
//AutoMark font style
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
lpSyntaxFile->dwAutoMarkFontStyle=(DWORD)xatoiW(wszBuffer, NULL);
}
//AutoMark text color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwAutoMarkTextColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//AutoMark background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwAutoMarkBkColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
break;
}
}
else if (!xstrcmpiW(wszBuffer, L"Quotes:") ||
!xstrcmpiW(wszBuffer, L"QuotesRE:"))
{
for (;;)
{
//Parse line
lpQuoteElement=NULL;
wpQuoteStart=NULL;
wpQuoteEnd=NULL;
wpQuoteInclude=NULL;
nQuoteIncludeLen=0;
wpQuoteExclude=NULL;
nQuoteExcludeLen=0;
wchEscape=0;
dwFlags=AEHLF_MATCHCASE;
dwFontStyle=0;
dwColor1=(DWORD)-1;
dwColor2=(DWORD)-1;
nParentID=0;
nRuleID=0;
for (;;)
{
//Highlight flags
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
dwFlags=(DWORD)xatoiW(wszBuffer, NULL);
if (dwFlags == 0 && wszBuffer[0] != L'0') break;
}
else goto SectionStart;
//Regular expression pattern, if quoted or font style, if number.
if (!(nQuoteStartLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack)))
break;
if (bQuoteString)
{
dwFlags|=AEHLF_REGEXP;
//Pattern
if (wpQuoteStart=(wchar_t *)GlobalAlloc(GPTR, (nQuoteStartLen + 1) * sizeof(wchar_t)))
xmemcpy(wpQuoteStart, wszBuffer, (nQuoteStartLen + 1) * sizeof(wchar_t));
else
break;
//Match map
if ((nQuoteEndLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack)) || bQuoteString)
{
if (nExpandLen=ExpandVars(wszBuffer, nQuoteEndLen, NULL, 0, lpVarStack))
if (wpQuoteEnd=(wchar_t *)GlobalAlloc(GPTR, nExpandLen * sizeof(wchar_t)))
nQuoteEndLen=(int)ExpandVars(wszBuffer, nQuoteEndLen, wpQuoteEnd, nExpandLen, lpVarStack);
}
else break;
}
else
{
//Font style
dwFontStyle=(DWORD)xatoiW(wszBuffer, NULL);
//Color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
dwColor1=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
else break;
//Background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
dwColor2=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
else break;
//Quote start
if ((nQuoteStartLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack)) || bQuoteString)
{
if (wpQuoteStart=(wchar_t *)GlobalAlloc(GPTR, (nQuoteStartLen + 1) * sizeof(wchar_t)))
xmemcpy(wpQuoteStart, wszBuffer, (nQuoteStartLen + 1) * sizeof(wchar_t));
else
break;
}
else break;
//Quote end
if ((nQuoteEndLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack)) || bQuoteString)
{
if (wpQuoteEnd=(wchar_t *)GlobalAlloc(GPTR, (nQuoteEndLen + 1) * sizeof(wchar_t)))
xmemcpy(wpQuoteEnd, wszBuffer, (nQuoteEndLen + 1) * sizeof(wchar_t));
else
break;
}
else break;
//Escape
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack) || bQuoteString)
wchEscape=wszBuffer[0];
else
break;
//Quote include
if ((nQuoteIncludeLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack)) || bQuoteString)
{
if (wpQuoteInclude=(wchar_t *)GlobalAlloc(GPTR, (nQuoteIncludeLen + 1) * sizeof(wchar_t)))
xmemcpy(wpQuoteInclude, wszBuffer, (nQuoteIncludeLen + 1) * sizeof(wchar_t));
else
break;
}
else break;
//Quote exclude
if ((nQuoteExcludeLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack)) || bQuoteString)
{
if (wpQuoteExclude=(wchar_t *)GlobalAlloc(GPTR, (nQuoteExcludeLen + 1) * sizeof(wchar_t)))
xmemcpy(wpQuoteExclude, wszBuffer, (nQuoteExcludeLen + 1) * sizeof(wchar_t));
else
break;
}
else break;
}
//Parent ID
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
nParentID=(int)xatoiW(wszBuffer, NULL);
//Rule ID
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
nRuleID=(int)xatoiW(wszBuffer, NULL);
}
}
//Add to stack
if (lpQuoteElement=StackInsertQuote(&lpSyntaxFile->hQuoteStack, nQuoteStartLen))
{
lpQuoteElement->wpQuoteStart=wpQuoteStart;
lpQuoteElement->nQuoteStartLen=nQuoteStartLen;
lpQuoteElement->wpQuoteEnd=wpQuoteEnd;
lpQuoteElement->nQuoteEndLen=nQuoteEndLen;
lpQuoteElement->wchEscape=wchEscape;
lpQuoteElement->wpQuoteInclude=wpQuoteInclude;
lpQuoteElement->nQuoteIncludeLen=nQuoteIncludeLen;
lpQuoteElement->wpQuoteExclude=wpQuoteExclude;
lpQuoteElement->nQuoteExcludeLen=nQuoteExcludeLen;
lpQuoteElement->dwFlags=dwFlags;
lpQuoteElement->dwFontStyle=dwFontStyle;
lpQuoteElement->dwColor1=dwColor1;
lpQuoteElement->dwColor2=dwColor2;
lpQuoteElement->nParentID=nParentID;
lpQuoteElement->nRuleID=nRuleID;
}
break;
}
if (!lpQuoteElement)
{
if (wpQuoteStart) GlobalFree((HGLOBAL)wpQuoteStart);
if (wpQuoteEnd) GlobalFree((HGLOBAL)wpQuoteEnd);
if (wpQuoteInclude) GlobalFree((HGLOBAL)wpQuoteInclude);
if (wpQuoteExclude) GlobalFree((HGLOBAL)wpQuoteExclude);
}
if (!NextLine(&wpText)) goto FreeText;
if (bSyntaxFileLoadError) goto FreeText;
}
}
else if (!xstrcmpiW(wszBuffer, L"Words:"))
{
for (;;)
{
//Parse line
lpWordElement=NULL;
wpWord=NULL;
dwFlags=AEHLF_MATCHCASE;
dwFontStyle=0;
dwColor1=(DWORD)-1;
dwColor2=(DWORD)-1;
nParentID=0;
for (;;)
{
//Highlight flags
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
dwFlags=(DWORD)xatoiW(wszBuffer, NULL);
if (dwFlags == 0 && wszBuffer[0] != L'0') break;
}
else goto SectionStart;
//Font style
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
dwFontStyle=(DWORD)xatoiW(wszBuffer, NULL);
}
else break;
//Color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
dwColor1=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
else break;
//Background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
dwColor2=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
else break;
//Word
if (nWordLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (wpWord=(wchar_t *)GlobalAlloc(GPTR, (nWordLen + 1) * sizeof(wchar_t)))
xmemcpy(wpWord, wszBuffer, (nWordLen + 1) * sizeof(wchar_t));
else
break;
}
else break;
//Parent ID
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
nParentID=(int)xatoiW(wszBuffer, NULL);
}
//Add to stack
if (lpWordElement=StackInsertWord(&lpSyntaxFile->hWordStack, &lpSyntaxFile->hWordAlphaStack, &lpSyntaxFile->hWordOrderStack, wpWord, nWordLen))
{
lpWordElement->wpWord=wpWord;
lpWordElement->nWordLen=nWordLen;
lpWordElement->dwFlags=dwFlags;
lpWordElement->dwFontStyle=dwFontStyle;
lpWordElement->dwColor1=dwColor1;
lpWordElement->dwColor2=dwColor2;
lpWordElement->nParentID=nParentID;
}
break;
}
if (!lpWordElement && wpWord) GlobalFree((HGLOBAL)wpWord);
if (!NextLine(&wpText)) goto FreeText;
if (bSyntaxFileLoadError) goto FreeText;
}
}
//CodeFold
else if (!xstrcmpiW(wszBuffer, L"FoldPanel:"))
{
//Parse line
for (;;)
{
lpSyntaxFile->dwFoldPanelFirstBkColor=(DWORD)-1;
lpSyntaxFile->dwFoldPanelSecondBkColor=(DWORD)-1;
lpSyntaxFile->dwFoldPanelNormalFoldColor=(DWORD)-1;
lpSyntaxFile->dwFoldPanelActiveFoldColor=(DWORD)-1;
lpSyntaxFile->dwFoldPanelNormalNodeOpenBkColor=(DWORD)-1;
lpSyntaxFile->dwFoldPanelNormalNodeCloseBkColor=(DWORD)-1;
lpSyntaxFile->dwFoldPanelActiveNodeOpenBkColor=(DWORD)-1;
lpSyntaxFile->dwFoldPanelActiveNodeCloseBkColor=(DWORD)-1;
lpSyntaxFile->dwFoldPanelNormalNodeOpenSignColor=(DWORD)-1;
lpSyntaxFile->dwFoldPanelNormalNodeCloseSignColor=(DWORD)-1;
lpSyntaxFile->dwFoldPanelActiveNodeOpenSignColor=(DWORD)-1;
lpSyntaxFile->dwFoldPanelActiveNodeCloseSignColor=(DWORD)-1;
//First background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldPanelFirstBkColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//Second background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldPanelSecondBkColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//Normal fold color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldPanelNormalFoldColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//Active fold color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldPanelActiveFoldColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//Normal node open background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldPanelNormalNodeOpenBkColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//Normal node close background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldPanelNormalNodeCloseBkColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//Active node open background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldPanelActiveNodeOpenBkColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//Active node close background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldPanelActiveNodeCloseBkColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//Normal node open sign color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldPanelNormalNodeOpenSignColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//Normal node close sign color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldPanelNormalNodeCloseSignColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//Active node open sign color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldPanelActiveNodeOpenSignColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//Active node close sign color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldPanelActiveNodeCloseSignColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
break;
}
}
else if (!xstrcmpiW(wszBuffer, L"FoldList:"))
{
//Parse line
for (;;)
{
lpSyntaxFile->dwFoldListTextColor=(DWORD)-1;
lpSyntaxFile->dwFoldListBkColor=(DWORD)-1;
//List text color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldListTextColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//List background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwFoldListBkColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
break;
}
}
else if (!xstrcmpiW(wszBuffer, L"TagMark:"))
{
//Parse line
for (;;)
{
lpSyntaxFile->dwTagMarkFlags=0;
lpSyntaxFile->dwTagMarkFontStyle=AEHLS_NONE;
lpSyntaxFile->dwTagMarkTextColor=(DWORD)-1;
lpSyntaxFile->dwTagMarkBkColor=(DWORD)-1;
//TagMark flags
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
lpSyntaxFile->dwTagMarkFlags=(DWORD)xatoiW(wszBuffer, NULL);
if (lpSyntaxFile->dwTagMarkFlags == 0 && wszBuffer[0] != L'0') break;
}
//TagMark font style
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
lpSyntaxFile->dwTagMarkFontStyle=(DWORD)xatoiW(wszBuffer, NULL);
}
//TagMark text color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwTagMarkTextColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//TagMark background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwTagMarkBkColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
break;
}
}
else if (!xstrcmpiW(wszBuffer, L"Skips:"))
{
for (;;)
{
//Parse line
lpSkipInfo=NULL;
wpSkipStart=NULL;
wpSkipEnd=NULL;
dwFlags=FIF_MATCHCASE;
for (;;)
{
//Skip flags
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
dwFlags=(DWORD)xatoiW(wszBuffer, NULL);
if (dwFlags == 0 && wszBuffer[0] != L'0') break;
}
else goto SectionStart;
//Skip start
if ((nSkipStartLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack)) || bQuoteString)
{
if (wpSkipStart=(wchar_t *)GlobalAlloc(GPTR, (nSkipStartLen + 1) * sizeof(wchar_t)))
xmemcpy(wpSkipStart, wszBuffer, (nSkipStartLen + 1) * sizeof(wchar_t));
else
break;
}
else break;
//Skip end
if ((nSkipEndLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack)) || bQuoteString)
{
if (wpSkipEnd=(wchar_t *)GlobalAlloc(GPTR, (nSkipEndLen + 1) * sizeof(wchar_t)))
xmemcpy(wpSkipEnd, wszBuffer, (nSkipEndLen + 1) * sizeof(wchar_t));
else
break;
}
else break;
//Escape
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack) || bQuoteString)
wchEscape=wszBuffer[0];
else
break;
//Add to stack
if (lpSkipInfo=StackInsertSkipInfo(&lpSyntaxFile->hSkipStack))
{
lpSkipInfo->dwFlags=dwFlags;
if (!(lpSkipInfo->lpSkipStart=StackInsertSkipStart(&lpSyntaxFile->hSkipStartStack, lpSkipInfo, wpSkipStart, nSkipStartLen)))
goto FreeSkip;
if (dwFlags & FIF_REGEXPEND)
{
lpSkipInfo->sregEnd.dwOptions=REO_MULTILINE|(dwFlags & FIF_MATCHCASE?REO_MATCHCASE:0);
lpSkipInfo->sregEnd.ref100=&lpSkipInfo->lpSkipStart->sregStart;
if (nSkipEndLen && !PatCompile(&lpSkipInfo->sregEnd, wpSkipEnd, wpSkipEnd + nSkipEndLen))
{
lpSkipInfo->sregEnd.first->dwFlags&=~REGF_ROOTANY;
nSkipEndLen=(int)lpSkipInfo->sregEnd.first->nGroupLen;
}
else
{
xprintfW(wszMessage, GetLangStringW(wLangModule, STRID_REGEXP_COMPILEERROR), lpSyntaxFile->wszSyntaxFileName, nSkipEndLen, wpSkipEnd);
MessageBoxW(hMainWnd, wszMessage, wszPluginTitle, MB_OK|MB_ICONEXCLAMATION);
goto FreeSkip;
}
}
lpSkipInfo->wpSkipEnd=wpSkipEnd;
lpSkipInfo->nSkipEndLen=nSkipEndLen;
lpSkipInfo->wchEscape=wchEscape;
break;
FreeSkip:
StackDelete((stack **)&lpSyntaxFile->hSkipStack.first, (stack **)&lpSyntaxFile->hSkipStack.last, (stack *)lpSkipInfo);
lpSkipInfo=NULL;
}
break;
}
if (!lpSkipInfo)
{
if (wpSkipStart) GlobalFree((HGLOBAL)wpSkipStart);
if (wpSkipEnd) GlobalFree((HGLOBAL)wpSkipEnd);
}
if (!NextLine(&wpText)) goto FreeText;
if (bSyntaxFileLoadError) goto FreeText;
}
}
else if (!xstrcmpiW(wszBuffer, L"Folds:"))
{
for (;;)
{
//Parse line
lpFoldInfo=NULL;
wpFoldStart=NULL;
wpFoldEnd=NULL;
wpFoldDelimiters=NULL;
wpRuleFile=NULL;
dwFlags=FIF_MATCHCASE;
dwFontStyle=0;
dwColor1=(DWORD)-1;
dwColor2=(DWORD)-1;
nParentID=0;
nRuleID=0;
wpLineStart=wpText;
for (;;)
{
//Fold flags
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
dwFlags=(DWORD)xatoiW(wszBuffer, NULL);
if (dwFlags == 0 && wszBuffer[0] != L'0') break;
}
else goto SectionStart;
//Font style
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
dwFontStyle=(DWORD)xatoiW(wszBuffer, NULL);
}
else break;
//Color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
dwColor1=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
else break;
//Background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
dwColor2=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
else break;
//Fold start
if ((nFoldStartLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack)) || bQuoteString)
{
if (wpFoldStart=(wchar_t *)GlobalAlloc(GPTR, (nFoldStartLen + 1) * sizeof(wchar_t)))
xmemcpy(wpFoldStart, wszBuffer, (nFoldStartLen + 1) * sizeof(wchar_t));
else
break;
}
else break;
//Fold end
if ((nFoldEndLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack)) || bQuoteString)
{
if (wpFoldEnd=(wchar_t *)GlobalAlloc(GPTR, (nFoldEndLen + 1) * sizeof(wchar_t)))
xmemcpy(wpFoldEnd, wszBuffer, (nFoldEndLen + 1) * sizeof(wchar_t));
else
break;
}
else break;
//Delimiters
if ((nDelimitersLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, &bQuoteString, lpVarStack)) || bQuoteString)
{
if (wpFoldDelimiters=(wchar_t *)GlobalAlloc(GPTR, (nDelimitersLen + 1) * sizeof(wchar_t)))
xmemcpy(wpFoldDelimiters, wszBuffer, (nDelimitersLen + 1) * sizeof(wchar_t));
else
break;
}
else break;
//Parent ID
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
nParentID=(int)xatoiW(wszBuffer, NULL);
//Rule ID
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
nRuleID=(int)xatoiW(wszBuffer, NULL);
//Rule file
if ((nRuleLen=GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack)))
{
if (wpRuleFile=(wchar_t *)GlobalAlloc(GPTR, (nRuleLen + 1) * sizeof(wchar_t)))
xmemcpy(wpRuleFile, wszBuffer, (nRuleLen + 1) * sizeof(wchar_t));
else
break;
}
}
}
//Add to stack
if (lpFoldInfo=StackInsertFoldInfo(&lpSyntaxFile->hFoldStack))
{
if (dwFlags & FIF_XMLTAG)
{
if (*wpFoldStart == L'<')
{
if (nFoldStartLen == 1)
{
if (!xstrcmpW(wpFoldEnd, L"</"))
dwFlags|=FIF_XMLNONAME_TWOTAG;
else if (!xstrcmpW(wpFoldEnd, L"/>"))
dwFlags|=FIF_XMLNONAME_ONETAG;
}
else if (nFoldEndLen > 0)
{
if (!xstrcmpnW(wpFoldEnd, L"</", 2))
dwFlags|=FIF_XMLNAMED_TWOTAG;
else if (wpFoldEnd[nFoldEndLen - 1] == L'>')
dwFlags|=FIF_XMLNAMED_ONETAG;
}
}
else if (nParentID)
{
dwFlags|=FIF_XMLCHILD;
}
}
lpFoldInfo->dwFlags=dwFlags;
lpFoldInfo->wpFoldEnd=wpFoldEnd;
lpFoldInfo->nFoldEndLen=nFoldEndLen;
lpFoldInfo->wpDelimiters=wpFoldDelimiters;
lpFoldInfo->dwFontStyle=dwFontStyle;
lpFoldInfo->dwColor1=dwColor1;
lpFoldInfo->dwColor2=dwColor2;
lpFoldInfo->nParentID=nParentID;
lpFoldInfo->nRuleID=nRuleID;
lpFoldInfo->wpRuleFile=wpRuleFile;
lpFoldInfo->crSyntaxFileLine.cpMin=wpLineStart - wpTextStart;
lpFoldInfo->crSyntaxFileLine.cpMax=wpText - wpTextStart;
if (!(lpFoldInfo->lpFoldStart=StackInsertFoldStart(&lpSyntaxFile->hFoldStartStack, lpFoldInfo, wpFoldStart, nFoldStartLen)))
goto FreeFold;
if (dwFlags & FIF_REGEXPEND)
{
lpFoldInfo->sregEnd.dwOptions=REO_MULTILINE|(dwFlags & FIF_MATCHCASE?REO_MATCHCASE:0);
lpFoldInfo->sregEnd.ref100=&lpFoldInfo->lpFoldStart->sregStart;
if (nFoldEndLen && !PatCompile(&lpFoldInfo->sregEnd, wpFoldEnd, wpFoldEnd + nFoldEndLen))
{
lpFoldInfo->sregEnd.first->dwFlags&=~REGF_ROOTANY;
lpFoldInfo->nFoldEndPointLen=(int)lpFoldInfo->sregEnd.first->nGroupLen;
}
else
{
xprintfW(wszMessage, GetLangStringW(wLangModule, STRID_REGEXP_COMPILEERROR), lpSyntaxFile->wszSyntaxFileName, nFoldEndLen, wpFoldEnd);
MessageBoxW(hMainWnd, wszMessage, wszPluginTitle, MB_OK|MB_ICONEXCLAMATION);
goto FreeFold;
}
}
else lpFoldInfo->nFoldEndPointLen=nFoldEndLen;
if (dwFlags & FIF_REGEXPSTART)
lpSyntaxFile->hFoldStack.nCommonFirstChar=-1;
else if (lpSyntaxFile->hFoldStack.nCommonFirstChar != -1)
{
if (!lpSyntaxFile->hFoldStack.nCommonFirstChar)
lpSyntaxFile->hFoldStack.nCommonFirstChar=*wpFoldStart;
else if ((wchar_t)lpSyntaxFile->hFoldStack.nCommonFirstChar != *lpFoldInfo->lpFoldStart->wpFoldStart)
lpSyntaxFile->hFoldStack.nCommonFirstChar=-1;
}
if (!(dwFlags & FIF_NOLISTFOLD))
lpSyntaxFile->hFoldStack.bVisible=TRUE;
if (lpFoldInfo->wpRuleFile)
++lpSyntaxFile->hFoldStack.nFoldWithThemeCount;
break;
FreeFold:
StackDeleteFoldInfo(&lpSyntaxFile->hFoldStack, &lpSyntaxFile->hFoldStartStack, lpFoldInfo);
lpFoldInfo=NULL;
wpFoldStart=NULL;
wpFoldEnd=NULL;
wpFoldDelimiters=NULL;
}
break;
}
if (!lpFoldInfo)
{
if (wpFoldStart) GlobalFree((HGLOBAL)wpFoldStart);
if (wpFoldEnd) GlobalFree((HGLOBAL)wpFoldEnd);
if (wpFoldDelimiters) GlobalFree((HGLOBAL)wpFoldDelimiters);
}
if (!NextLine(&wpText)) goto FreeText;
if (bSyntaxFileLoadError) goto FreeText;
}
}
//AutoComplete
else if (!xstrcmpiW(wszBuffer, L"CompleteList:"))
{
//Parse line
for (;;)
{
lpSyntaxFile->dwCompleteListFontStyle=0;
lpSyntaxFile->nCompleteListFontSize=0;
lpSyntaxFile->wszCompleteListFaceName[0]=L'\0';
lpSyntaxFile->nCompleteListLineGap=0;
lpSyntaxFile->wszCompleteListBlockIcon[0]=L'\0';
lpSyntaxFile->dwCompleteListBlockIconMargins=0;
lpSyntaxFile->wszCompleteListHlBaseIcon[0]=L'\0';
lpSyntaxFile->dwCompleteListHlBaseIconMargins=0;
lpSyntaxFile->wszCompleteListDocWordIcon[0]=L'\0';
lpSyntaxFile->dwCompleteListDocWordIconMargins=0;
lpSyntaxFile->dwCompleteListIcons=0;
lpSyntaxFile->dwCompleteListBasicTextColor=(DWORD)-1;
lpSyntaxFile->dwCompleteListBasicBkColor=(DWORD)-1;
lpSyntaxFile->dwCompleteListSelTextColor=(DWORD)-1;
lpSyntaxFile->dwCompleteListSelBkColor=(DWORD)-1;
//Font style
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
lpSyntaxFile->dwCompleteListFontStyle=(DWORD)xatoiW(wszBuffer, NULL);
}
//Font size
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
lpSyntaxFile->nCompleteListFontSize=(int)xatoiW(wszBuffer, NULL);
}
//Face name
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
xstrcpynW(lpSyntaxFile->wszCompleteListFaceName, wszBuffer, LF_FACESIZE);
}
//Line gap
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
lpSyntaxFile->nCompleteListLineGap=(int)xatoiW(wszBuffer, NULL);
}
//Block icon
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
xstrcpynW(lpSyntaxFile->wszCompleteListBlockIcon, wszBuffer, MAX_PATH);
if (*lpSyntaxFile->wszCompleteListBlockIcon)
lpSyntaxFile->dwCompleteListIcons|=BIT_BLOCK;
}
//Block icon margins
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
StrToArray(wszBuffer, &lpSyntaxFile->dwCompleteListBlockIconMargins, sizeof(DWORD), sizeof(WORD), NULL);
}
//HighLight base icon
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
xstrcpynW(lpSyntaxFile->wszCompleteListHlBaseIcon, wszBuffer, MAX_PATH);
if (*lpSyntaxFile->wszCompleteListHlBaseIcon)
lpSyntaxFile->dwCompleteListIcons|=BIT_HLBASE;
}
//HighLight base icon margins
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
StrToArray(wszBuffer, &lpSyntaxFile->dwCompleteListHlBaseIconMargins, sizeof(DWORD), sizeof(WORD), NULL);
}
//Document word icon
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
xstrcpynW(lpSyntaxFile->wszCompleteListDocWordIcon, wszBuffer, MAX_PATH);
if (*lpSyntaxFile->wszCompleteListDocWordIcon)
lpSyntaxFile->dwCompleteListIcons|=BIT_DOCWORD;
}
//Document word icon margins
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
StrToArray(wszBuffer, &lpSyntaxFile->dwCompleteListDocWordIconMargins, sizeof(DWORD), sizeof(WORD), NULL);
}
//List basic text color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwCompleteListBasicTextColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//List basic background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwCompleteListBasicBkColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//List sel text color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwCompleteListSelTextColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
//List sel background color
if (GetWord(wpText, wszBuffer, BUFFER_SIZE, &wpText, NULL, lpVarStack))
{
if (*wszBuffer == L'#')
{
lpSyntaxFile->dwCompleteListSelBkColor=GetColorFromStr(wszBuffer + 1, NULL);
}
else if (*wszBuffer != L'0') break;
}
break;
}
}
else if (!xstrcmpiW(wszBuffer, L"Blocks:"))
{
BLOCKINFO *lpBlockMaster;
BLOCKINFO *lpBlockInfo;
BLOCKINFOHANDLE *lpBlockInfoHandle;
TITLEINFO *lpTitleInfo;
STACKREGROUP *sregTitle;
const wchar_t *wpTitleBegin;
wchar_t *wszTitle;
const wchar_t *wpBlockBegin;
const wchar_t *wpBlockEnd;
wchar_t *wszBlockParsed;
STACKTITLE hTitleStack;
HSTACK hHotSpotStack;
DWORD dwTitleFlags;
int nTitleLen;
while (*wpText)
{
lpBlockMaster=NULL;
lpBlockInfo=NULL;
lpTitleInfo=NULL;
sregTitle=NULL;
wpTitleBegin=NULL;
wszTitle=NULL;
wszBlockParsed=NULL;
hTitleStack.first=0;
hTitleStack.last=0;
hHotSpotStack.first=0;
hHotSpotStack.last=0;
dwTitleFlags=0;
bExactTitle=-1;
//Title
while (*wpText)
{
if (*wpText == L'$')
{
if (*++wpText == L';' || *wpText == L'#')
{
//Skip comment
if (!NextLine(&wpText))
break;
continue;
}
if (*wpText == L'(')
{
dwTitleFlags=(DWORD)xatoiW(wpText + 1, &wpText);
if (*wpText == L')')
++wpText;
else
break;
}
if (*wpText == L'~' || *wpText == L'=')
{
if (*wpText == L'~')
bExactTitle=FALSE;
else
bExactTitle=TRUE;
wpTitleBegin=++wpText;
while (*wpText != L' ' && *wpText != L'\t' && *wpText != L'\r' && *wpText != L'\0') ++wpText;
nTitleLen=(int)(wpText - wpTitleBegin);
if (nTitleLen)
{
if (wszTitle=(wchar_t *)GlobalAlloc(GPTR, (nTitleLen + 1) * sizeof(wchar_t)))
{
xmemcpy(wszTitle, wpTitleBegin, nTitleLen * sizeof(wchar_t));
wszTitle[nTitleLen]=L'\0';
if (lpTitleInfo=StackInsertTitle(&hTitleStack))
{
if (bExactTitle && (dwTitleFlags & TF_REGEXP))
{
if (sregTitle=(STACKREGROUP *)GlobalAlloc(GPTR, sizeof(STACKREGROUP)))
{
sregTitle->dwOptions=REO_MULTILINE;
if (bCompleteCaseSensitive)
sregTitle->dwOptions|=REO_MATCHCASE;
if (dwTitleFlags & TF_FORCECASESENSITIVE)
sregTitle->dwOptions|=REO_MATCHCASE;
else if (dwTitleFlags & TF_FORCECASEINSENSITIVE)
sregTitle->dwOptions&=~REO_MATCHCASE;
if (PatCompile(sregTitle, wszTitle, wszTitle + nTitleLen))
{
xprintfW(wszMessage, GetLangStringW(wLangModule, STRID_REGEXP_COMPILEERROR), lpSyntaxFile->wszSyntaxFileName, nTitleLen, wszTitle);
MessageBoxW(hMainWnd, wszMessage, wszPluginTitle, MB_OK|MB_ICONEXCLAMATION);
goto FreeBlock;
}
//sregTitle->first->dwFlags&=~REGF_ROOTANY;
lpTitleInfo->sregTitle=sregTitle;
sregTitle=NULL;
}
else goto FreeBlock;
}
lpTitleInfo->wpTitle=wszTitle;
lpTitleInfo->nTitleLen=nTitleLen;
lpTitleInfo->dwTitleFlags=dwTitleFlags;
lpTitleInfo->bExactTitle=bExactTitle;
}
else break;
wszTitle=NULL;
}
else break;
}
}
else break;
}
if (*wpText == L'\r')
{
NextLine(&wpText);
break;
}
++wpText;
}
//Title block
if (*wpText && hTitleStack.first)
{
wpBlockBegin=wpText;
while (*wpText)
{
if (*wpText == L'$')
{
//Find next abbreviation definition
if (*++wpText == L'~' || *wpText == L'=' || *wpText == L'(')
{
--wpText;
break;
}
}
if (!NextLine(&wpText))
break;
}
wpBlockEnd=wpText;
nBlockLen=(int)(wpBlockEnd - wpBlockBegin);
if (nBlockParsedLen=ParseBlock(lpSyntaxFile, &hHotSpotStack, wpBlockBegin, nBlockLen, NULL, NULL))
{
if (wszBlockParsed=(wchar_t *)GlobalAlloc(GPTR, nBlockParsedLen * sizeof(wchar_t)))
{
nBlockParsedLen=ParseBlock(lpSyntaxFile, &hHotSpotStack, wpBlockBegin, nBlockLen, wszBlockParsed, &nLinesInBlock);
if (nBlockParsedLen > 0 && wszBlockParsed[nBlockParsedLen - 1] == L'\r') wszBlockParsed[--nBlockParsedLen]=L'\0';
if (nBlockParsedLen > 0 && wszBlockParsed[nBlockParsedLen - 1] == L'\r') wszBlockParsed[--nBlockParsedLen]=L'\0';
for (lpTitleInfo=(TITLEINFO *)hTitleStack.first; lpTitleInfo; lpTitleInfo=lpTitleInfo->next)
{
if (lpTitleInfo->bExactTitle)
lpBlockInfo=StackInsertExactBlock(&lpSyntaxFile->hExactBlockStack);
else
lpBlockInfo=StackInsertBlock(&lpSyntaxFile->hBlockStack, &lpSyntaxFile->hBlockOrderStack, lpTitleInfo->wpTitle);
if (lpBlockInfo)
{
lpBlockInfo->wpTitle=lpTitleInfo->wpTitle;
lpBlockInfo->nTitleLen=lpTitleInfo->nTitleLen;
lpBlockInfo->dwTitleFlags=lpTitleInfo->dwTitleFlags;
lpBlockInfo->bExactTitle=lpTitleInfo->bExactTitle;
lpBlockInfo->sregTitle=lpTitleInfo->sregTitle;
if (lpTitleInfo == (TITLEINFO *)hTitleStack.first)
{
lpBlockMaster=lpBlockInfo;
lpBlockInfo->master=NULL;
lpBlockInfo->wpBlock=wszBlockParsed;
lpBlockInfo->nBlockLen=nBlockParsedLen;
lpBlockInfo->nLinesInBlock=nLinesInBlock;
lpBlockInfo->hHotSpotStack=hHotSpotStack;
}
else lpBlockInfo->master=lpBlockMaster;
if (hTitleStack.first != hTitleStack.last)
{
//Multiple abbreviations
if (!StackInsertIndex((stack **)&lpBlockMaster->firstHandle, (stack **)&lpBlockMaster->lastHandle, (stack **)&lpBlockInfoHandle, -1, sizeof(BLOCKINFOHANDLE)))
{
lpBlockInfoHandle->lpBlockInfo=lpBlockInfo;
}
}
}
}
wszBlockParsed=NULL;
}
}
}
//Free
FreeBlock:
if (!lpBlockInfo)
StackFreeHotSpot(&hHotSpotStack);
StackFreeTitle(&hTitleStack);
if (sregTitle) GlobalFree((HGLOBAL)sregTitle);
if (wszTitle) GlobalFree((HGLOBAL)wszTitle);
if (wszBlockParsed) GlobalFree((HGLOBAL)wszBlockParsed);
}
}
else
{
xprintfW(wszMessage, GetLangStringW(wLangModule, STRID_UNKNOWNSECTION), lpSyntaxFile->wszSyntaxFileName, wpSectionStart - wpTextStart, wszBuffer);
MessageBoxW(hMainWnd, wszMessage, wszPluginTitle, MB_OK|MB_ICONEXCLAMATION);
goto FreeText;
}
goto SectionStart;
}
lpLoadSyntaxFile=NULL;
}
FreeText:
GlobalFree((HGLOBAL)wszText);
}
}
}
CloseHandle(hFile);
return lpSyntaxFile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment