/* * Wordch tells whether character at *wc is a word character * i.e. an alfa, digit, or underscore. */ int wordch(char *wc) { int c; #ifdef MB if (mb_cur_max > 0 && *wc & 0200) { mbtowi(&c, wc, mb_cur_max); if (c & INVBIT) return 1; } else #endif c = wc[0]&0377; return (xisalnum(c) || c == '_' #ifdef BIT8 #ifdef ISO8859_1 /* * We consider all ISO 8859-1 characters except for * no-break-space as word characters. */ || c&0200 && (!(c"E) && (c&TRIM) != 0240) #endif #endif ); }
DWORD CCrystalTextView:: ParseLineFortran (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems) { int nLength = GetLineLength (nLineIndex); if (nLength == 0) return dwCookie & COOKIE_EXT_COMMENT; LPCTSTR pszChars = GetLineChars (nLineIndex); bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0; bool bRedefineBlock = true; bool bDecIndex = false; int nIdentBegin = -1; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos)))) { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = true; bDecIndex = true; goto out; } } bRedefineBlock = false; bDecIndex = false; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "...." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = true; } continue; } // Char constant '..' if (dwCookie & COOKIE_CHAR) { if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_CHAR; bRedefineBlock = true; } continue; } if (pszChars[I] == '!' || !I && (pszChars[I] == 'C' || pszChars[I] == 'c')) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // Normal text if (pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if (pszChars[I] == '\'') { // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'') if (!I || !xisalnum (pszChars[nPrevI])) { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_CHAR; continue; } } if (bFirstChar) { if (!xisspace (pszChars[I])) bFirstChar = false; } if (pBuf == NULL) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1]))) { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (IsFortranKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsFortranNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } bRedefineBlock = true; bDecIndex = true; nIdentBegin = -1; } } } if (nIdentBegin >= 0) { if (IsFortranKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsFortranNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } } if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1)) dwCookie &= COOKIE_EXT_COMMENT; return dwCookie; }
DWORD CrystalLineParser::ParseLineAsp (DWORD dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems) { if (nLength == 0) return dwCookie & (COOKIE_EXT_COMMENT|COOKIE_EXT_USER1); bool bFirstChar = (dwCookie & ~(COOKIE_EXT_COMMENT|COOKIE_EXT_USER1)) == 0; bool bRedefineBlock = true; bool bDecIndex = false; int nIdentBegin = -1; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = static_cast<int>(::CharNext(pszChars+I) - pszChars)) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else if (dwCookie & COOKIE_PREPROCESSOR) { DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR); } else if (dwCookie & COOKIE_EXT_USER1) { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.') { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = true; bDecIndex = true; goto out; } } bRedefineBlock = false; bDecIndex = false; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength || pszChars[I] == 0) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "...." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = true; } continue; } // Char constant '..' if (dwCookie & COOKIE_CHAR) { if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_CHAR; bRedefineBlock = true; } continue; } // Extended comment <!--....--> if (dwCookie & COOKIE_EXT_COMMENT) { if (!(dwCookie & COOKIE_EXT_USER1)) { if (I > 1 && pszChars[I] == '>' && pszChars[nPrevI] == '-' && *::CharPrev(pszChars, pszChars + nPrevI) == '-') { dwCookie &= ~COOKIE_EXT_COMMENT; bRedefineBlock = true; } } continue; } if ((dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '\'') { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // Extended comment <?....?> if (dwCookie & COOKIE_EXT_USER1) { if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%')) { dwCookie &= ~COOKIE_EXT_USER1; bRedefineBlock = true; continue; } } // Normal text if ((dwCookie & (COOKIE_PREPROCESSOR|COOKIE_EXT_USER1)) && pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if ((dwCookie & (COOKIE_PREPROCESSOR|COOKIE_EXT_USER1)) && pszChars[I] == '\'') { // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'') if (!I || !xisalnum (pszChars[nPrevI])) { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_CHAR; continue; } } if (!(dwCookie & COOKIE_EXT_USER1)) { if (!(dwCookie & COOKIE_EXT_USER1) && I < nLength - 3 && pszChars[I] == '<' && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-') { DEFINE_BLOCK (I, COLORINDEX_COMMENT); I += 3; dwCookie |= COOKIE_EXT_COMMENT; dwCookie &= ~COOKIE_PREPROCESSOR; continue; } } if (bFirstChar) { if (!xisspace (pszChars[I])) bFirstChar = false; } // User1 start: <? if (I < nLength && pszChars[I] == '<' && I < nLength - 1 && (pszChars[I + 1] == '?' || pszChars[I + 1] == '%')) { DEFINE_BLOCK (I, COLORINDEX_NORMALTEXT); dwCookie |= COOKIE_EXT_USER1; nIdentBegin = -1; continue; } if (pBuf == nullptr) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '.') { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (dwCookie & COOKIE_PREPROCESSOR) { if (IsHtmlKeyword (pszChars + nIdentBegin, I - nIdentBegin) && (pszChars[nIdentBegin - 1] == _T ('<') || pszChars[nIdentBegin - 1] == _T ('/'))) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsAspNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { goto next; } } else if (dwCookie & COOKIE_EXT_USER1) { if (IsAspKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsAspNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = false; for (int j = I; j < nLength; j++) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = true; } break; } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } else { goto next; } } } else if (dwCookie & COOKIE_USER1) { if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } else { goto next; } } bRedefineBlock = true; bDecIndex = true; nIdentBegin = -1; next: ; } // Preprocessor start: < or bracket if (!(dwCookie & COOKIE_EXT_USER1) && I < nLength && pszChars[I] == '<' && !(I < nLength - 3 && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-')) { DEFINE_BLOCK (I, COLORINDEX_OPERATOR); DEFINE_BLOCK (I + 1, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; nIdentBegin = -1; continue; } // User1 end: ?> if (dwCookie & COOKIE_EXT_USER1) { if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%')) { dwCookie &= ~COOKIE_EXT_USER1; nIdentBegin = -1; bRedefineBlock = true; bDecIndex = true; continue; } } // Preprocessor end: > or bracket if (dwCookie & COOKIE_PREPROCESSOR) { if (pszChars[I] == '>') { dwCookie &= ~COOKIE_PREPROCESSOR; nIdentBegin = -1; bRedefineBlock = true; bDecIndex = true; continue; } } // Preprocessor start: & if (!(dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '&') { dwCookie |= COOKIE_USER1; nIdentBegin = -1; continue; } // Preprocessor end: ; if (dwCookie & COOKIE_USER1) { if (pszChars[I] == ';') { dwCookie &= ~COOKIE_USER1; nIdentBegin = -1; continue; } } } } if (nIdentBegin >= 0 && (dwCookie & COOKIE_PREPROCESSOR)) { if (IsHtmlKeyword (pszChars + nIdentBegin, I - nIdentBegin) && (pszChars[nIdentBegin - 1] == _T ('<') || pszChars[nIdentBegin - 1] == _T ('/'))) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } else if (IsAspNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = false; for (int j = I; j < nLength; j++) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = true; } break; } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } } } else if (nIdentBegin >= 0 && (dwCookie & COOKIE_EXT_USER1)) { if (IsAspKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsAspNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = false; for (int j = I; j < nLength; j++) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = true; } break; } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } } } dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_STRING | COOKIE_PREPROCESSOR | COOKIE_EXT_USER1); return dwCookie; }
DWORD CrystalLineParser::ParseLineIni (DWORD dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems) { if (nLength == 0) return dwCookie & COOKIE_EXT_COMMENT; bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0; bool bRedefineBlock = true; bool bDecIndex = false; int nIdentBegin = -1; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = static_cast<int>(::CharNext(pszChars+I) - pszChars)) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else if (dwCookie & COOKIE_SECTION) { DEFINE_BLOCK (nPos, COLORINDEX_FUNCNAME); } else if (dwCookie & COOKIE_KEY) { DEFINE_BLOCK (nPos, COLORINDEX_KEYWORD); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos)))) { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = true; bDecIndex = true; goto out; } } bRedefineBlock = false; bDecIndex = false; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength || pszChars[I] == 0) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "...." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = true; } continue; } // Char constant '..' if (dwCookie & COOKIE_CHAR) { if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_CHAR; bRedefineBlock = true; } continue; } // Section header [...] if (dwCookie & COOKIE_SECTION) { if (pszChars[I] == ']') { dwCookie &= ~COOKIE_SECTION; bRedefineBlock = true; } continue; } // Key if (dwCookie & COOKIE_KEY) { if (I + 1 < nLength && pszChars[I + 1] == '=') { dwCookie &= ~COOKIE_KEY; bRedefineBlock = true; } continue; } // Normal text if (pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if (pszChars[I] == '\'') { // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'') if (!I || !xisalnum (pszChars[nPrevI])) { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_CHAR; continue; } } if (bFirstChar) { if (pszChars[I] == ';') // Comment { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } else if (pszChars[I] == '[') // Section header [...] { DEFINE_BLOCK (I, COLORINDEX_FUNCNAME); dwCookie |= COOKIE_SECTION; continue; } else // Key { DEFINE_BLOCK (I, COLORINDEX_KEYWORD); dwCookie |= COOKIE_KEY; } if (!xisspace (pszChars[I])) bFirstChar = false; } if (pBuf == nullptr) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1]))) { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (IsIniNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } bRedefineBlock = true; bDecIndex = true; nIdentBegin = -1; } } } if (nIdentBegin >= 0) { if (IsIniNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } } dwCookie &= COOKIE_EXT_COMMENT; return dwCookie; }
DWORD CCrystalTextView:: ParseLineVerilog (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems) { int nLength = GetLineLength (nLineIndex); if (nLength == 0) return dwCookie & COOKIE_EXT_COMMENT; LPCTSTR pszChars = GetLineChars (nLineIndex); bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0; bool bRedefineBlock = true; bool bWasCommentStart = false; bool bDecIndex = false; int nIdentBegin = -1; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = static_cast<int>(::CharNext(pszChars+I) - pszChars)) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else if (dwCookie & COOKIE_PREPROCESSOR) { DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '$' || (pszChars[nPos] == '\'' && nPos > 0 && (xisalpha (*::CharNext(pszChars + nPos))))) { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = true; bDecIndex = true; goto out; } } bRedefineBlock = false; bDecIndex = false; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "..." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = true; } continue; } // Extended comment /*...*/ if (dwCookie & COOKIE_EXT_COMMENT) { if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*')) { dwCookie &= ~COOKIE_EXT_COMMENT; bRedefineBlock = true; } bWasCommentStart = false; continue; } // Line comment //... if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // Preprocessor directive `... if (dwCookie & COOKIE_PREPROCESSOR) { if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; } continue; } // Normal text if (pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; bWasCommentStart = true; continue; } bWasCommentStart = false; if (bFirstChar) { if (pszChars[I] == '`') { DEFINE_BLOCK (I, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; continue; } if (!xisspace (pszChars[I])) bFirstChar = false; } if (pBuf == NULL) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '$' || pszChars[I] == '\'') { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (IsVerilogKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsVerilogFunction (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsVerilogNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } bRedefineBlock = true; bDecIndex = true; nIdentBegin = -1; } } } if (nIdentBegin >= 0) { if (IsVerilogKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsVerilogFunction (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } else if (IsVerilogNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } } dwCookie &= COOKIE_EXT_COMMENT; return dwCookie; }
DWORD CCrystalTextView:: ParseLineSiod (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems) { int nLength = GetLineLength (nLineIndex); if (nLength == 0) return dwCookie & COOKIE_EXT_COMMENT; LPCTSTR pszChars = GetLineChars (nLineIndex); BOOL bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0; BOOL bRedefineBlock = TRUE; BOOL bWasCommentStart = FALSE; BOOL bDecIndex = FALSE; int nIdentBegin = -1; BOOL bDefun = FALSE; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = ::CharNext(pszChars+I) - pszChars) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.') { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = TRUE; bDecIndex = TRUE; goto out; } } bRedefineBlock = FALSE; bDecIndex = FALSE; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "...." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = TRUE; } continue; } // Char constant '..' if (dwCookie & COOKIE_CHAR) { if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_CHAR; bRedefineBlock = TRUE; } continue; } // Extended comment /*....*/ if (dwCookie & COOKIE_EXT_COMMENT) { // if (I > 0 && pszChars[I] == ';' && pszChars[nPrevI] == '|') if ((I > 1 && pszChars[I] == ';' && pszChars[nPrevI] == '|' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != ';'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == ';' && pszChars[nPrevI] == '|')) { dwCookie &= ~COOKIE_EXT_COMMENT; bRedefineBlock = TRUE; } bWasCommentStart = FALSE; continue; } if (I > 0 && pszChars[I] != '|' && pszChars[nPrevI] == ';') { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // Normal text if (pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if (pszChars[I] == '\'') { // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'') if (!I || !xisalnum (pszChars[nPrevI])) { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_CHAR; continue; } } if (I > 0 && pszChars[I] == '|' && pszChars[nPrevI] == ';') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; bWasCommentStart = TRUE; continue; } bWasCommentStart = FALSE; if (bFirstChar) { if (!xisspace (pszChars[I])) bFirstChar = FALSE; } if (pBuf == NULL) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '.') { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (IsSiodKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { if (!_tcsnicmp (_T ("defun"), pszChars + nIdentBegin, 5)) { bDefun = TRUE; } DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } else if (IsSiodNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = FALSE; if (!bDefun) { for (int j = nIdentBegin; --j >= 0;) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = TRUE; } break; } } } if (!bFunction) { for (int j = I; j >= 0; j--) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = TRUE; } break; } } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } } bRedefineBlock = TRUE; bDecIndex = TRUE; nIdentBegin = -1; } } } if (nIdentBegin >= 0) { if (IsSiodKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { if (!_tcsnicmp (_T ("defun"), pszChars + nIdentBegin, 5)) { bDefun = TRUE; } DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } else if (IsSiodNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = FALSE; if (!bDefun) { for (int j = nIdentBegin; --j >= 0;) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = TRUE; } break; } } } if (!bFunction) { for (int j = I; j >= 0; j--) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = TRUE; } break; } } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } } } dwCookie &= COOKIE_EXT_COMMENT; return dwCookie; }
void Find_AutoComplete(HWND hwnd) { LPEDITINTERFACE lpInterface = PCP_Edit_GetInterface(hwnd); POINT ptCursorPos = PCP_Edit_GetCursorPos(lpInterface); int nLength = PCP_Edit_GetLineLength(lpInterface, ptCursorPos.y); LPCTSTR pszText = PCP_Edit_GetLineChars(lpInterface, ptCursorPos.y); LPCTSTR pszEnd = pszText + ptCursorPos.x; if (ptCursorPos.x > 0 && ptCursorPos.y > 0 && (nLength == ptCursorPos.x || !xisalnum(*pszEnd)) && xisalnum(pszEnd[-1])) { LPCTSTR pszBegin = pszEnd - 1; LPTSTR pszBuffer; POINT ptTextPos; BOOL bFound; EDITSEARCHINFO esi; while (pszBegin > pszText && xisalnum(*pszBegin)) pszBegin--; if (!xisalnum(*pszBegin)) pszBegin++; nLength = pszEnd - pszBegin; pszBuffer = (LPTSTR)Mem_AllocStr(nLength + 1 + SZ); *pszBuffer = _T('<'); _tcsncpy(pszBuffer + 1, pszBegin, nLength); pszBuffer[nLength + 1] = _T('\0'); ptCursorPos.x -= nLength; bFound = PCP_Edit_FindText(lpInterface, pszBuffer, ptCursorPos, PE_FIND_MATCH_CASE|PE_FIND_REG_EXP|PE_FIND_DIRECTION_UP, TRUE, &ptTextPos); if (!bFound) { ptCursorPos.x += nLength; bFound = PCP_Edit_FindText(lpInterface, pszBuffer, ptCursorPos, FIND_MATCH_CASE|FIND_REG_EXP, TRUE, &ptTextPos); ptCursorPos.x -= nLength; } if (bFound) { int nFound = PCP_Edit_GetLineLength(lpInterface, ptTextPos.y); LPTSTR psz; PCP_Edit_GetSearchInfo(lpInterface, &esi); pszText = PCP_Edit_GetLineChars(lpInterface, ptTextPos.y) + ptTextPos.x + lpInterface->iLastFindWhatLen; nFound -= ptTextPos.x + esi.nLastSearchLen; Mem_Free(pszBuffer); psz = pszBuffer = (LPTSTR)Mem_AllocStr(nFound + SZ); while (nFound-- && xisalnum(*pszText)) *psz++ = *pszText++; *psz = _T('\0'); if ((pszBuffer[0] != _T('\0'))) { int x, y; PCP_Edit_BeginUndoGroup(lpInterface, FALSE); PCP_Edit_InsertText(lpInterface, ptCursorPos.y, ptCursorPos.x + nLength, pszBuffer, &y, &x, PE_ACTION_AUTOCOMPLETE); ptCursorPos.x = x; ptCursorPos.y = y; PCP_Edit_SetCursorPos(lpInterface, ptCursorPos); PCP_Edit_SetSelection(lpInterface, ptCursorPos, ptCursorPos); PCP_Edit_SetAnchor(lpInterface, ptCursorPos); PCP_Edit_EnsureVisible(lpInterface, ptCursorPos); PCP_Edit_FlushUndoGroup(lpInterface); } Mem_Free(pszBuffer); } } }
DWORD CrystalLineParser::ParseLineNsis (DWORD dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems) { if (nLength == 0) return dwCookie & COOKIE_EXT_COMMENT; bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0; bool bRedefineBlock = true; bool bWasCommentStart = false; bool bDecIndex = false; int nIdentBegin = -1; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = static_cast<int>(::CharNext(pszChars+I) - pszChars)) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else if (dwCookie & COOKIE_PREPROCESSOR) { DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos)))) { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = true; bDecIndex = true; goto out; } } bRedefineBlock = false; bDecIndex = false; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength || pszChars[I] == 0) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "...." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = true; } continue; } // Char constant '..' if (dwCookie & COOKIE_CHAR) { if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_CHAR; bRedefineBlock = true; } continue; } // Extended comment /*....*/ if (dwCookie & COOKIE_EXT_COMMENT) { // if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '*') if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*')) { dwCookie &= ~COOKIE_EXT_COMMENT; bRedefineBlock = true; } bWasCommentStart = false; continue; } //if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/') if (I > 0 && pszChars[nPrevI] == ';') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // Preprocessor directive #.... if (dwCookie & COOKIE_PREPROCESSOR) { if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; } continue; } // Normal text if (pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if (pszChars[I] == '\'') { // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'') if (!I || !xisalnum (pszChars[nPrevI])) { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_CHAR; continue; } } if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; bWasCommentStart = true; continue; } bWasCommentStart = false; if (bFirstChar) { if (pszChars[I] == '!') { DEFINE_BLOCK (I, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; continue; } if (!xisspace (pszChars[I])) bFirstChar = false; } if (pBuf == nullptr) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1]))) { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (IsNsisKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsNsisNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = false; for (int j = I; j < nLength; j++) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = true; } break; } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } } bRedefineBlock = true; bDecIndex = true; nIdentBegin = -1; } } } if (nIdentBegin >= 0) { if (IsNsisKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsNsisNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = false; for (int j = I; j < nLength; j++) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = true; } break; } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } } } if (pszChars[nLength - 1] != '\\' || IsMBSTrail(pszChars, nLength - 1)) dwCookie &= COOKIE_EXT_COMMENT; return dwCookie; }
DWORD CCrystalTextView:: ParseLineInnoSetup (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems) { int nLength = GetLineLength (nLineIndex); if (nLength == 0) return dwCookie & (COOKIE_EXT_COMMENT | COOKIE_EXT_COMMENT2); LPCTSTR pszChars = GetLineChars (nLineIndex); BOOL bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0; BOOL bRedefineBlock = TRUE; BOOL bDecIndex = FALSE; int nIdentBegin = -1; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT | COOKIE_EXT_COMMENT2)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else if (dwCookie & COOKIE_PREPROCESSOR) { DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR); } else if (dwCookie & COOKIE_SECTION) { DEFINE_BLOCK (nPos, COLORINDEX_FUNCNAME); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos)))) { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = TRUE; bDecIndex = TRUE; goto out; } } bRedefineBlock = FALSE; bDecIndex = FALSE; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "...." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = TRUE; } continue; } // Char constant '..' if (dwCookie & COOKIE_CHAR) { if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_CHAR; bRedefineBlock = TRUE; } continue; } // Extended comment (*....*) if (dwCookie & COOKIE_EXT_COMMENT) { // if (I > 0 && pszChars[I] == ')' && pszChars[nPrevI] == '*') if ((I > 1 && pszChars[I] == ')' && pszChars[nPrevI] == '*' && *::CharPrev(pszChars, pszChars + nPrevI) != '(') || (I == 1 && pszChars[I] == ')' && pszChars[nPrevI] == '*')) { dwCookie &= ~COOKIE_EXT_COMMENT; bRedefineBlock = TRUE; } continue; } // Extended comment {....} if (dwCookie & COOKIE_EXT_COMMENT2) { if (pszChars[I] == '}') { dwCookie &= ~COOKIE_EXT_COMMENT2; bRedefineBlock = TRUE; } continue; } if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // Section header [...] if (dwCookie & COOKIE_SECTION) { if (pszChars[I] == ']') { dwCookie &= ~COOKIE_SECTION; bRedefineBlock = TRUE; } continue; } // Normal text if (pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if (pszChars[I] == '\'') { // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'') if (!I || !xisalnum (pszChars[nPrevI])) { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_CHAR; continue; } } if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '(') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; continue; } if (pszChars[I] == '{') { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT2; continue; } if (bFirstChar) { if (pszChars[I] == ';') { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; continue; } if (pszChars[I] == '#') { DEFINE_BLOCK (I, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; continue; } if (pszChars[I] == '[') { DEFINE_BLOCK (I, COLORINDEX_FUNCNAME); dwCookie |= COOKIE_SECTION; continue; } if (!xisspace (pszChars[I])) bFirstChar = FALSE; } if (pBuf == NULL) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1]))) { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (IsInnoSetupKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsInnoSetupNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = FALSE; for (int j = I; j < nLength; j++) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = TRUE; } break; } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } } bRedefineBlock = TRUE; bDecIndex = TRUE; nIdentBegin = -1; } } } if (nIdentBegin >= 0) { if (IsInnoSetupKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsInnoSetupNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { bool bFunction = FALSE; for (int j = I; j < nLength; j++) { if (!xisspace (pszChars[j])) { if (pszChars[j] == '(') { bFunction = TRUE; } break; } } if (bFunction) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME); } } } if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1)) dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_EXT_COMMENT2); return dwCookie; }
void parse_refreshCheckHelper(refresh_check_helper ** ptr) { refresh_check_helper *a; char *token; refresh_check_format **p; if (*ptr) self_destruct(); CBDATA_INIT_TYPE_FREECB(refresh_check_helper, free_refresh_check_helper); CBDATA_INIT_TYPE_FREECB(refresh_check_format, free_refresh_check_format); a = cbdataAlloc(refresh_check_helper); a->children = DEFAULT_REFRESH_CHECK_CHILDREN; /* Parse options */ while ((token = strtok(NULL, w_space)) != NULL) { if (strncmp(token, "children=", 9) == 0) { a->children = atoi(token + 9); } else if (strncmp(token, "concurrency=", 12) == 0) { a->concurrency = atoi(token + 12); } else { break; } } /* Parse format */ p = &a->format; while (token) { refresh_check_format *format; /* stop on first non-format token found */ if (*token != '%') break; format = cbdataAlloc(refresh_check_format); if (strncmp(token, "%RES{", 5) == 0) { /* header format */ char *header, *member, *end; header = token + 5; end = strchr(header, '}'); /* cut away the terminating } */ if (end && strlen(end) == 1) *end = '\0'; else self_destruct(); member = strchr(header, ':'); if (member) { /* Split in header and member */ *member++ = '\0'; if (!xisalnum(*member)) format->separator = *member++; else format->separator = ','; format->member = xstrdup(member); format->type = REFRESH_CHECK_RESP_HEADER_MEMBER; } else { format->type = REFRESH_CHECK_RESP_HEADER; } format->header = xstrdup(header); format->header_id = httpHeaderIdByNameDef(header, strlen(header)); if (format->header_id != -1) { if (member) format->type = REFRESH_CHECK_RESP_HEADER_ID_MEMBER; else format->type = REFRESH_CHECK_RESP_HEADER_ID; } } else if (strcmp(token, "%URI") == 0) format->type = REFRESH_CHECK_URI; else if (strcmp(token, "%URL") == 0) format->type = REFRESH_CHECK_URI; else if (strcmp(token, "%CACHE_URI") == 0) format->type = REFRESH_CHECK_URI; else if (strcmp(token, "%AGE") == 0) format->type = REFRESH_CHECK_AGE; else { self_destruct(); } *p = format; p = &format->next; token = strtok(NULL, w_space); } /* There must be at least one format token */ if (!a->format) self_destruct(); /* helper */ if (!token) self_destruct(); wordlistAdd(&a->cmdline, token); /* arguments */ parse_wordlist(&a->cmdline); *ptr = a; }
DWORD Edit_Syntax_ParseLineGeneric(LPEDITVIEW lpew, DWORD dwCookie, int nLineIndex, LPTEXTBLOCK pBuf, int *piActualItems) { int nLength = Edit_View_GetLineLength(lpew, nLineIndex); LPCTSTR pszChars = Edit_View_GetLineChars(lpew, nLineIndex); LPTEXTDEF lptd = lpew->lptdCurSourceDef; BOOL bFirstChar = (dwCookie & ~(COOKIE_EXT_COMMENT)) == 0; BOOL bRedefineBlock = TRUE; BOOL bWasCommentStart = FALSE; BOOL bDecIndex = FALSE; int nIdentBegin = -1; int i; int nCommentLen; if (nLength <= 0) return (dwCookie & COOKIE_EXT_COMMENT); for (i = 0; ; i++) { if (bRedefineBlock) { int nPos = i; if (bDecIndex) nPos--; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK(nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK(nPos, COLORINDEX_STRING); } else if (dwCookie & COOKIE_PREPROCESSOR) { DEFINE_BLOCK(nPos, COLORINDEX_PREPROCESSOR); } else if (dwCookie & COOKIE_PREFIXED) { DEFINE_BLOCK(nPos, COLORINDEX_PREFIXED); } else { if (Edit_Syntax_IsOperator(lptd, pszChars[nPos])) { DEFINE_BLOCK(nPos, COLORINDEX_OPERATOR); bRedefineBlock = TRUE; bDecIndex = TRUE; goto out; } else /* if ((xisalnum(pszChars[nPos]) || pszChars[nPos] == _T('.') && nPos > 0 && (!xisalfa(pszChars[nPos - 1]) && !xisalfa(pszChars[nPos + 1]))))*/ { DEFINE_BLOCK(nPos, COLORINDEX_NORMALTEXT); } /* else { DEFINE_BLOCK(nPos, COLORINDEX_OPERATOR); bRedefineBlock = TRUE; bDecIndex = TRUE; goto out; }*/ } bRedefineBlock = FALSE; bDecIndex = FALSE; } out: if (i >= nLength) break; // Line Comment ? [//] if (dwCookie & COOKIE_COMMENT) { if ((!lptd->bCommentFirstRealChar) || (lptd->bCommentFirstRealChar && bFirstChar)) { DEFINE_BLOCK(i, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } } // String constant ? ["..."] if (dwCookie & COOKIE_STRING) { if (pszChars[i] == lptd->cString && (i == 0 || i == 1 && pszChars[i - 1] != lptd->cEscape || i >= 2 && (pszChars[i - 1] != lptd->cEscape || pszChars[i - 1] == lptd->cEscape && pszChars[i - 2] == lptd->cEscape))) { dwCookie &= ~(COOKIE_STRING); bRedefineBlock = TRUE; } // Nasty but functions...just a good proof that // this whole function needs rewriting if (lptd->bPrefixesInStrings) { if (bRedefineBlock && (dwCookie & COOKIE_PREFIXED)) dwCookie |= COOKIE_STRING; if (dwCookie & COOKIE_PREFIXED) { if (!xisalnum(pszChars[i])) { dwCookie &= ~(COOKIE_PREFIXED); bRedefineBlock = TRUE; // We have to reevaluate the last char i--; } else { DEFINE_BLOCK(i, COLORINDEX_PREFIXED); } } else { if (Edit_Syntax_IsPrefix(lptd, pszChars + i)) { DEFINE_BLOCK(i, COLORINDEX_PREFIXED); dwCookie |= COOKIE_PREFIXED; } } } continue; } // Char constant ? ['...'] if (dwCookie & COOKIE_CHAR) { if (pszChars[i] == lptd->cChar && (i == 0 || i == 1 && pszChars[i - 1] != lptd->cEscape || i >= 2 && (pszChars[i - 1] != lptd->cEscape || pszChars[i - 1] == lptd->cEscape && pszChars[i - 2] == lptd->cEscape))) { dwCookie &= ~(COOKIE_CHAR); bRedefineBlock = TRUE; } continue; } // Extended comment End ? [*/] if (dwCookie & COOKIE_EXT_COMMENT) { if (((i > (lptd->nCloseCommentLen - 1) && lptd->nCloseCommentLen > 0 && String_NumEqual((pszChars + i - lptd->nCloseCommentLen), lptd->szCloseComment, lptd->nCloseCommentLen, lptd->bCase) && !bWasCommentStart) || (i >= (lptd->nCloseCommentLen - 1) && lptd->nCloseCommentLen > 0 && String_NumEqual((pszChars + i - (lptd->nCloseCommentLen - 1)), lptd->szCloseComment, lptd->nCloseCommentLen, lptd->bCase))) || ((i > (lptd->nCloseComment2Len - 1) && lptd->nCloseComment2Len > 0 && String_NumEqual((pszChars + i - lptd->nCloseComment2Len), lptd->szCloseComment2, lptd->nCloseComment2Len, lptd->bCase) && !bWasCommentStart) || (i >= (lptd->nCloseComment2Len - 1) && lptd->nCloseComment2Len > 0 && String_NumEqual((pszChars + i - (lptd->nCloseComment2Len - 1)), lptd->szCloseComment2, lptd->nCloseComment2Len, lptd->bCase)))) { dwCookie &= ~(COOKIE_EXT_COMMENT); bRedefineBlock = TRUE; } bWasCommentStart = FALSE; continue; } if (dwCookie & COOKIE_PREFIXED) { if (!xisalnum(pszChars[i])) { dwCookie &= ~(COOKIE_PREFIXED); bRedefineBlock = TRUE; // We have to reevaluate the last char i--; } else { DEFINE_BLOCK(i, COLORINDEX_PREFIXED); } continue; } if (dwCookie & COOKIE_DISABLED) { if (pszChars[i] == lptd->cEnable && (i == 0 || i == 1 && pszChars[i - 1] != lptd->cEscape || i >= 2 && (pszChars[i - 1] != lptd->cEscape || pszChars[i - 1] == lptd->cEscape && pszChars[i - 2] == lptd->cEscape))) { dwCookie &= ~(COOKIE_DISABLED); bRedefineBlock = TRUE; } continue; } // if the line end char is there than the next char will be the first // in that pseudoline if (pszChars[i] == lptd->cLineEnd) { bFirstChar = TRUE; goto ProcessWord; // continue; } // Start Processing // if the char is a linecontinuation char then assume error in user code // or already parsed from previous line // Just break because it does so in MSDEV damnit! =P if (pszChars[i] == lptd->cLineContinuation) { DEFINE_BLOCK(i, COLORINDEX_NORMALTEXT); break; } // Line Comment [//] if (((i >= ((nCommentLen = lptd->nLineCommentLen) - 1) && lptd->nLineCommentLen > 0 && String_NumEqual((pszChars + i - (lptd->nLineCommentLen - 1)), lptd->szLineComment, lptd->nLineCommentLen, lptd->bCase))) || (i >= ((nCommentLen = lptd->nLineComment2Len) - 1) && lptd->nLineComment2Len > 0 && String_NumEqual((pszChars + i - (lptd->nLineComment2Len - 1)), lptd->szLineComment2, lptd->nLineComment2Len, lptd->bCase))) { if ((!lptd->bCommentFirstRealChar) || (lptd->bCommentFirstRealChar && bFirstChar)) { DEFINE_BLOCK(i - (nCommentLen - 1), COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } } // Preprocessor directive [#] if (dwCookie & COOKIE_PREPROCESSOR) { if (((i >= ((nCommentLen = lptd->nOpenCommentLen) - 1) && lptd->nOpenCommentLen > 0 && String_NumEqual((pszChars + i - (lptd->nOpenCommentLen - 1)), lptd->szOpenComment, lptd->nOpenCommentLen, lptd->bCase))) || (i >= ((nCommentLen = lptd->nOpenComment2Len) - 1) && lptd->nOpenComment2Len > 0 && String_NumEqual((pszChars + i - (lptd->nOpenComment2Len - 1)), lptd->szOpenComment2, lptd->nOpenComment2Len, lptd->bCase))) { DEFINE_BLOCK(i - (nCommentLen - 1), COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; } continue; } // Normal text // String ["..."] if (pszChars[i] == lptd->cString) { if (i > 0 && pszChars[i - 1] == lptd->cEscape) continue; DEFINE_BLOCK(i, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } // Char ['...'] if (pszChars[i] == lptd->cChar) { if (i > 0 && pszChars[i - 1] == lptd->cEscape) continue; DEFINE_BLOCK(i, COLORINDEX_STRING); dwCookie |= COOKIE_CHAR; continue; } // Open Comment [/*] if (((i >= ((nCommentLen = lptd->nOpenCommentLen) - 1) && lptd->nOpenCommentLen > 0 && String_NumEqual((pszChars + i - (lptd->nOpenCommentLen - 1)), lptd->szOpenComment, lptd->nOpenCommentLen, lptd->bCase))) || (i >= ((nCommentLen = lptd->nOpenComment2Len) - 1) && lptd->nOpenComment2Len > 0 && String_NumEqual((pszChars + i - (lptd->nOpenComment2Len - 1)), lptd->szOpenComment2, lptd->nOpenComment2Len, lptd->bCase))) { if ((!lptd->bCommentFirstRealChar) || (lptd->bCommentFirstRealChar && bFirstChar)) { DEFINE_BLOCK(i - (nCommentLen - 1), COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; bWasCommentStart = TRUE; } continue; } bWasCommentStart = FALSE; if (bFirstChar) { // Preprocessor [#] if (pszChars[i] == lptd->cPreProcessor) { DEFINE_BLOCK(i, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; continue; } // if it is whitespace then still available if (!_istspace(pszChars[i])) bFirstChar = FALSE; } // FIXME: does this work with lptd->cEscape? if (Edit_Syntax_IsPrefix(lptd, pszChars + i)) { DEFINE_BLOCK(i, COLORINDEX_PREFIXED); dwCookie |= COOKIE_PREFIXED; continue; } if (pszChars[i] == lptd->cDisable) { if (i > 0 && pszChars[i - 1] == lptd->cEscape) continue; DEFINE_BLOCK(i, COLORINDEX_NORMALTEXT); dwCookie |= COOKIE_DISABLED; continue; } // We don't need to extract keywords, // for faster parsing skip the rest of loop if (pBuf == NULL) continue; if (xisalnum(pszChars[i]) || pszChars[i] == _T('.') && i > 0 && (!xisalpha(pszChars[i - 1]) && !xisalpha(pszChars[i + 1]))) { if (nIdentBegin == -1) nIdentBegin = i; } else { ProcessWord: if (nIdentBegin >= 0) { if (Edit_Syntax_IsKeyword(lptd, pszChars + nIdentBegin, i - nIdentBegin)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_KEYWORD); } else if (Edit_Syntax_IsUser1Keyword(lptd, pszChars + nIdentBegin, i - nIdentBegin)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_USER1); } else if (Edit_Syntax_IsUser2Keyword(lptd, pszChars + nIdentBegin, i - nIdentBegin)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_USER2); } else if (Edit_Syntax_IsNumber(pszChars + nIdentBegin, i - nIdentBegin)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER); } else { BOOL bFunction = FALSE; int j; for (j = i; j < nLength; j++) { if (!_istspace(pszChars[j])) { if (pszChars[j] == lptd->cFunctionBegin) bFunction = TRUE; break; } } if (bFunction) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_FUNCNAME); } } bRedefineBlock = TRUE; bDecIndex = TRUE; nIdentBegin = -1; } else if (Edit_Syntax_IsOperator(lptd, pszChars[i])) { DEFINE_BLOCK(i, COLORINDEX_OPERATOR); bRedefineBlock = TRUE; bDecIndex = TRUE; } } } if (nIdentBegin >= 0) { if (Edit_Syntax_IsKeyword(lptd, pszChars + nIdentBegin, i - nIdentBegin)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_KEYWORD); } else if (Edit_Syntax_IsUser1Keyword(lptd, pszChars + nIdentBegin, i - nIdentBegin)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_USER1); } else if (Edit_Syntax_IsUser2Keyword(lptd, pszChars + nIdentBegin, i - nIdentBegin)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_USER2); } else if (Edit_Syntax_IsNumber(pszChars + nIdentBegin, i - nIdentBegin)) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER); } else { BOOL bFunction = FALSE; int j; for (j = i; j < nLength; j++) { if (!_istspace(pszChars[j])) { if (pszChars[j] == lptd->cFunctionBegin) bFunction = TRUE; break; } } if (bFunction) { DEFINE_BLOCK(nIdentBegin, COLORINDEX_FUNCNAME); } } } if (pszChars[nLength - 1] != lptd->cLineContinuation) { dwCookie &= ~(COOKIE_COMMENT); dwCookie &= ~(COOKIE_STRING); dwCookie &= ~(COOKIE_CHAR); dwCookie &= ~(COOKIE_PREFIXED); } return (dwCookie); }
DWORD CCrystalTextView:: ParseLineCss (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems) { int nLength = GetLineLength (nLineIndex); if (nLength == 0) return dwCookie & (COOKIE_EXT_COMMENT|COOKIE_EXT_DEFINITION|COOKIE_EXT_VALUE); LPCTSTR pszChars = GetLineChars (nLineIndex); BOOL bFirstChar = (dwCookie & ~(COOKIE_EXT_COMMENT|COOKIE_EXT_DEFINITION|COOKIE_EXT_VALUE)) == 0; BOOL bRedefineBlock = TRUE; BOOL bWasCommentStart = FALSE; BOOL bDecIndex = FALSE; int nIdentBegin = -1; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & COOKIE_EXT_COMMENT) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else { if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' || pszChars[nPos] == '-' || pszChars[nPos] == '%') { if (dwCookie & COOKIE_EXT_VALUE) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = TRUE; bDecIndex = TRUE; goto out; } } bRedefineBlock = FALSE; bDecIndex = FALSE; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength) break; // Extended definition {....} if (dwCookie & COOKIE_EXT_DEFINITION) { if (pszChars[I] == ':') //Value start... { dwCookie |= COOKIE_EXT_VALUE; } else if (pszChars[I] == ';') //Value end... { dwCookie &= ~COOKIE_EXT_VALUE; } else if (pszChars[I] == '}') //Definition end... { dwCookie &= ~COOKIE_EXT_DEFINITION; dwCookie &= ~COOKIE_EXT_VALUE; } } // Extended comment /*....*/ if (dwCookie & COOKIE_EXT_COMMENT) { if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*')) { dwCookie &= ~COOKIE_EXT_COMMENT; bRedefineBlock = TRUE; } bWasCommentStart = FALSE; continue; } // Normal text if (pszChars[I] == '{') { dwCookie |= COOKIE_EXT_DEFINITION; } if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/') { DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; bWasCommentStart = TRUE; continue; } bWasCommentStart = FALSE; if (bFirstChar) { if (!xisspace (pszChars[I])) bFirstChar = FALSE; } if (pBuf == NULL) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (xisalnum (pszChars[I]) || pszChars[I] == '.' || pszChars[I] == '-' || pszChars[I] == '%') { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if (dwCookie & COOKIE_EXT_VALUE) { if (IsCss1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsCss2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } else { goto next; } } bRedefineBlock = TRUE; bDecIndex = TRUE; nIdentBegin = -1; next: ; } } } if ((nIdentBegin >= 0) && (dwCookie & COOKIE_EXT_VALUE)) { if (IsCss1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsCss2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } } dwCookie &= (COOKIE_EXT_COMMENT|COOKIE_EXT_DEFINITION|COOKIE_EXT_VALUE); return dwCookie; }
DWORD CCrystalTextView:: ParseLineBatch (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems) { int nLength = GetLineLength (nLineIndex); if (nLength == 0) return dwCookie & COOKIE_EXT_COMMENT; LPCTSTR pszChars = GetLineChars (nLineIndex); bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0; bool bRedefineBlock = true; bool bDecIndex = false; int nIdentBegin = -1; int nPrevI = -1; int I=0; for (I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars) { if (I == nPrevI) { // CharNext did not advance, so we're at the end of the string // and we already handled this character, so stop break; } if (bRedefineBlock) { int nPos = I; if (bDecIndex) nPos = nPrevI; if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT)) { DEFINE_BLOCK (nPos, COLORINDEX_COMMENT); } else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING)) { DEFINE_BLOCK (nPos, COLORINDEX_STRING); } else if (dwCookie & COOKIE_PREPROCESSOR) { DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR); } else { if (pszChars[nPos] == _T ('_') || pszChars[nPos] == _T ('@') || xisalnum (pszChars[nPos]) || pszChars[nPos] == '.') { DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT); } else { DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR); bRedefineBlock = true; bDecIndex = true; goto out; } } bRedefineBlock = false; bDecIndex = false; } out: // Can be bigger than length if there is binary data // See bug #1474782 Crash when comparing SQL with with binary data if (I >= nLength) break; if (dwCookie & COOKIE_COMMENT) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } // String constant "...." if (dwCookie & COOKIE_STRING) { if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_STRING; bRedefineBlock = true; } continue; } // Char constant '..' if (dwCookie & COOKIE_CHAR) { if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\'))) { dwCookie &= ~COOKIE_CHAR; bRedefineBlock = true; } continue; } if (dwCookie & COOKIE_PREPROCESSOR) { DEFINE_BLOCK (I, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; break; } // Normal text if (pszChars[I] == '"') { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_STRING; continue; } if (pszChars[I] == '\'') { // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'') if (!I || !xisalnum (pszChars[nPrevI])) { DEFINE_BLOCK (I, COLORINDEX_STRING); dwCookie |= COOKIE_CHAR; continue; } } if (bFirstChar) { if (nLength >= I + 4 &&!_tcsnicmp (pszChars + I, _T ("TEXT"), 4)) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_EXT_COMMENT; continue; } if (nLength >= I + 7 &&!_tcsnicmp (pszChars + I, _T ("ENDTEXT"), 7)) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie &= ~COOKIE_EXT_COMMENT; continue; } if (dwCookie & COOKIE_EXT_COMMENT) continue; if (nLength >= I + 3 && !_tcsnicmp (pszChars + I, _T ("REM"), 3) && (xisspace (pszChars[I + 3]) || nLength == I + 3)) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } if (pszChars[I] == ':') { if (nLength > I + 2 && !(xisalnum (pszChars[I+1]) || xisspace (pszChars[I+1]))) { DEFINE_BLOCK (I, COLORINDEX_COMMENT); dwCookie |= COOKIE_COMMENT; break; } DEFINE_BLOCK (I, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; continue; } if (!xisspace (pszChars[I])) bFirstChar = false; } if (pBuf == NULL) continue; // We don't need to extract keywords, // for faster parsing skip the rest of loop if (pszChars[I] == _T ('_') || pszChars[I] == _T ('@') || xisalnum (pszChars[I]) || pszChars[I] == '.') { if (nIdentBegin == -1) nIdentBegin = I; } else { if (nIdentBegin >= 0) { if ((dwCookie & COOKIE_PREPROCESSOR)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_PREPROCESSOR); } else { if (dwCookie & COOKIE_EXT_COMMENT) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_COMMENT); } else if (IsBatKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); if ((I - nIdentBegin ==4 && !_tcsnicmp (pszChars + nIdentBegin, _T ("GOTO"), 4)) || (I - nIdentBegin ==5 && !_tcsnicmp (pszChars + nIdentBegin, _T ("GOSUB"), 5)) ) { dwCookie=COOKIE_PREPROCESSOR; } } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } else if (IsBatNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } } bRedefineBlock = true; bDecIndex = true; nIdentBegin = -1; } } } if (nIdentBegin >= 0) { if (dwCookie & COOKIE_EXT_COMMENT) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_COMMENT); } else if (IsBatKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); if ((I - nIdentBegin ==4 && !_tcsnicmp (pszChars + nIdentBegin, _T ("GOTO"), 4)) || (I - nIdentBegin ==5 && !_tcsnicmp (pszChars + nIdentBegin, _T ("GOSUB"), 5)) ) { dwCookie=COOKIE_PREPROCESSOR; } } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } else if (IsBatNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } } dwCookie &= COOKIE_EXT_COMMENT; return dwCookie; }