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:: 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 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; }
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 CCrystalEditView::OnEditTab() { if (! QueryEditable() || m_pTextBuffer == NULL) return; BOOL bTabify = FALSE; CPoint ptSelStart, ptSelEnd; if (IsSelection()) { GetSelection(ptSelStart, ptSelEnd); bTabify = ptSelStart.y != ptSelEnd.y; } if (bTabify) { m_pTextBuffer->BeginUndoGroup(); int nStartLine = ptSelStart.y; int nEndLine = ptSelEnd.y; ptSelStart.x = 0; if (ptSelEnd.x > 0) { if (ptSelEnd.y == GetLineCount() - 1) { ptSelEnd.x = GetLineLength(ptSelEnd.y); } else { ptSelEnd.x = 0; ptSelEnd.y ++; } } else nEndLine --; SetSelection(ptSelStart, ptSelEnd); SetCursorPos(ptSelEnd); EnsureVisible(ptSelEnd); // Shift selection to right m_bHorzScrollBarLocked = TRUE; static const TCHAR pszText[] = _T("\t"); for (int L = nStartLine; L <= nEndLine; L ++) { int x, y; m_pTextBuffer->InsertText(this, L, 0, pszText, y, x, CE_ACTION_INDENT); // [JRT] } m_bHorzScrollBarLocked = FALSE; RecalcHorzScrollBar(); m_pTextBuffer->FlushUndoGroup(this); return; } if (m_bOvrMode) { CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); int nLineLength = GetLineLength(ptCursorPos.y); LPCTSTR pszLineChars = GetLineChars(ptCursorPos.y); if (ptCursorPos.x < nLineLength) { int nTabSize = GetTabSize(); int nChars = nTabSize - CalculateActualOffset(ptCursorPos.y, ptCursorPos.x) % nTabSize; ASSERT(nChars > 0 && nChars <= nTabSize); while (nChars > 0) { if (ptCursorPos.x == nLineLength) break; if (pszLineChars[ptCursorPos.x] == _T('\t')) { ptCursorPos.x ++; break; } ptCursorPos.x ++; nChars --; } ASSERT(ptCursorPos.x <= nLineLength); ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); return; } } m_pTextBuffer->BeginUndoGroup(); DeleteCurrentSelection(); CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); static const TCHAR pszText[] = _T("\t"); int x, y; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); m_pTextBuffer->FlushUndoGroup(this); }
void CCrystalEditView::OnEditUntab() { if (! QueryEditable() || m_pTextBuffer == NULL) return; BOOL bTabify = FALSE; CPoint ptSelStart, ptSelEnd; if (IsSelection()) { GetSelection(ptSelStart, ptSelEnd); bTabify = ptSelStart.y != ptSelEnd.y; } if (bTabify) { m_pTextBuffer->BeginUndoGroup(); CPoint ptSelStart, ptSelEnd; GetSelection(ptSelStart, ptSelEnd); int nStartLine = ptSelStart.y; int nEndLine = ptSelEnd.y; ptSelStart.x = 0; if (ptSelEnd.x > 0) { if (ptSelEnd.y == GetLineCount() - 1) { ptSelEnd.x = GetLineLength(ptSelEnd.y); } else { ptSelEnd.x = 0; ptSelEnd.y ++; } } else nEndLine --; SetSelection(ptSelStart, ptSelEnd); SetCursorPos(ptSelEnd); EnsureVisible(ptSelEnd); // Shift selection to left m_bHorzScrollBarLocked = TRUE; for (int L = nStartLine; L <= nEndLine; L ++) { int nLength = GetLineLength(L); if (nLength > 0) { LPCTSTR pszChars = GetLineChars(L); int nPos = 0, nOffset = 0; while (nPos < nLength) { if (pszChars[nPos] == _T(' ')) { nPos ++; if (++ nOffset >= GetTabSize()) break; } else { if (pszChars[nPos] == _T('\t')) nPos ++; break; } } if (nPos > 0) m_pTextBuffer->DeleteText(this, L, 0, L, nPos, CE_ACTION_INDENT); // [JRT] } } m_bHorzScrollBarLocked = FALSE; RecalcHorzScrollBar(); m_pTextBuffer->FlushUndoGroup(this); } else { CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); if (ptCursorPos.x > 0) { int nTabSize = GetTabSize(); int nOffset = CalculateActualOffset(ptCursorPos.y, ptCursorPos.x); int nNewOffset = nOffset / nTabSize * nTabSize; if (nOffset == nNewOffset && nNewOffset > 0) nNewOffset -= nTabSize; ASSERT(nNewOffset >= 0); LPCTSTR pszChars = GetLineChars(ptCursorPos.y); int nCurrentOffset = 0; int I = 0; while (nCurrentOffset < nNewOffset) { if (pszChars[I] == _T('\t')) nCurrentOffset = nCurrentOffset / nTabSize * nTabSize + nTabSize; else nCurrentOffset ++; I ++; } ASSERT(nCurrentOffset == nNewOffset); ptCursorPos.x = I; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); } } }
int CCrystalEditView::FormatSelection(int nDelta) { CPoint pStartSel,pEndSel; CString sLineBuf,sBegin; GetSelection(pStartSel,pEndSel); int nStartLine,nEndLine,nLineL; nStartLine=pStartSel.y; nEndLine=pEndSel.y; char cTab[2] ={' ',0}; int nTabsCount=0; int nLC,firstFlg; nLC = nStartLine; firstFlg=1; sBegin=""; nLC-=1+nDelta; if(nLC<0) nLC=0; m_pTextBuffer->BeginUndoGroup(); CString csDelta;//левый отступ for(nLC;nLC<=nEndLine;nLC++) { sLineBuf = GetLineChars(nLC); nLineL = GetLineLength(nLC); //ищем левые пробелы for(int i=0;i<nLineL;i++) { if(IsLetter(sLineBuf.GetAt(i),1)) break; } //удаляем их if(i>0) { if(nStartLine-1-nDelta==nLC)//первая строка в выборке csDelta=sLineBuf.Left(i); m_pTextBuffer->DeleteText(this, nLC, 0, nLC, i, CE_ACTION_TYPING); } //добавляем нужное количество пробелов (табуляции) sLineBuf = GetLineChars(nLC); sLineBuf .TrimLeft(); CString sCutLineBuf; sCutLineBuf = sLineBuf.Left(9); sCutLineBuf.MakeUpper(); CString csSpaces=csDelta; //анализ "табов" для текущей позиции if (!sCutLineBuf.Find("ФУНКЦИЯ")) { nTabsCount=0; csSpaces="";//игнорирование пробелов в первой строке csDelta=""; } else if (!sCutLineBuf.Find("ПРОЦЕДУРА")) { nTabsCount=0; csSpaces=""; csDelta=""; } else if(sCutLineBuf.Left(1)=="#") continue; else if (!sCutLineBuf.Find("КОНЕЦПРОЦ")) { nTabsCount=0; csSpaces=""; csDelta=""; } else if (!sCutLineBuf.Find("КОНЕЦФУНК")) { nTabsCount=0; csSpaces=""; csDelta=""; } else if (!sCutLineBuf.Find("КОНЕЦ")) { nTabsCount--; //csSpaces=csSpaces.Left(csSpaces.GetLength()-1); } else if (!sCutLineBuf.Find("ИСКЛЮЧЕНИ")) { nTabsCount--; //csSpaces=csSpaces.Left(csSpaces.GetLength()-1); } else if (!sCutLineBuf.Find("ИНАЧЕ")) { nTabsCount--; //csSpaces=csSpaces.Left(csSpaces.GetLength()-1); } // if(nTabsCount<0) // nTabsCount=0; //Вставка пробелов for(int j=1;j<=nTabsCount;j++) csSpaces+=cTab; int x,y; if(!csSpaces.IsEmpty()) m_pTextBuffer->InsertText(this, nLC, 0,csSpaces,y,x, CE_ACTION_TYPING); //анализ "табов" для следующей позиции if (!sCutLineBuf.Find("ФУНКЦИЯ")) nTabsCount=1; if (!sCutLineBuf.Find("ПРОЦЕДУРА")) nTabsCount=1; if (!sCutLineBuf.Find("КОНЕЦ")); else if (!sCutLineBuf.Find("ДЛЯ")) nTabsCount++; else if (!sCutLineBuf.Find("ПОКА")) nTabsCount++; else if (!sCutLineBuf.Find("ЕСЛИ")) nTabsCount++; else if (!sCutLineBuf.Find("ПОПЫТКА")) nTabsCount++; else if (!sCutLineBuf.Find("ИНАЧЕ")) nTabsCount++; else if (!sCutLineBuf.Find("ИСКЛЮЧЕНИ")) nTabsCount++; } m_pTextBuffer->FlushUndoGroup(this); return 1; }
void CCrystalEditView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { CCrystalTextView::OnChar(nChar, nRepCnt, nFlags); if ((::GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0 || (::GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0) return; if (nChar ==32 || nChar == VK_RETURN) if(nCursorColor==COLORINDEX_NORMALTEXT||nCursorColor==COLORINDEX_KEYWORD) {//анализ на предмет использования шаблонов CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); if(ptCursorPos.y>=0&&ptCursorPos.y<GetLineCount()) { CString Str = GetLineChars(ptCursorPos.y); int nLength = GetLineLength(ptCursorPos.y); Str=Str.Left(min(ptCursorPos.x,nLength)); CValue vDeleteText; CValue vInsertText; extern int AfxCallInitProc(CString csName,CValue Param,CValue &vDeleteText,CValue &vInsertText); int nRet=AfxCallInitProc("ПриВыбореШаблона",String(Str),vDeleteText,vInsertText); if(nRet) { int nDeleteCount=vDeleteText.GetString().GetLength(); int nStartPos=max(0,ptCursorPos.x-nDeleteCount); if(nDeleteCount>0) m_pTextBuffer->DeleteText(this, ptCursorPos.y, nStartPos, ptCursorPos.y, ptCursorPos.x, CE_ACTION_TYPING); int x, y; CString csStrInsert=vInsertText.GetString(); m_pTextBuffer->InsertText(this, ptCursorPos.y, nStartPos, csStrInsert, y, x, CE_ACTION_TYPING); CPoint ptEnd; ptEnd.x=x; ptEnd.y=y; ptCursorPos.x=0; SetSelection(ptCursorPos, ptEnd); FormatSelection(0); ptEnd.y-=(csStrInsert.Replace("\r","\r")+1)/2; ptEnd.x=GetLineLength(ptEnd.y); SetSelection(ptEnd, ptEnd); SetAnchor(ptEnd); SetCursorPos(ptEnd); EnsureVisible(ptEnd); MoveEnd(0); } } } BOOL bTranslated = FALSE; if (nChar == VK_RETURN) { if (m_bOvrMode) { CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); if (ptCursorPos.y < GetLineCount() - 1) { ptCursorPos.x = 0; ptCursorPos.y++; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); return; } } m_pTextBuffer->BeginUndoGroup(); if (QueryEditable() && m_pTextBuffer != NULL) { DeleteCurrentSelection(); int x, y; CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); const static TCHAR pszText[3] = _T("\r\n"); m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); // [JRT] int nLenght = GetLineLength(ptCursorPos.y); CString sLineBuf = GetLineChars(ptCursorPos.y); CString sBegin=""; for(int i=0;i<=nLenght;i++) { char cChr; cChr = sLineBuf.GetAt(i); if(!IsLetter(cChr,1)) sBegin+=cChr; else break; } int nPos=ptCursorPos.x; m_pTextBuffer->InsertText(this,y,x, sBegin, y, x, CE_ACTION_TYPING); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); /* FormatSelection(-1); if(nPos>0) { MoveEnd(0); } */ } m_pTextBuffer->FlushUndoGroup(this); return; } if (nChar > 31) { if (QueryEditable() && m_pTextBuffer != NULL) { BOOL bUndoBeginGroup=m_pTextBuffer->m_bUndoGroup; if(!bUndoBeginGroup) m_pTextBuffer->BeginUndoGroup(nChar != _T(' ')); CPoint ptSelStart, ptSelEnd; GetSelection(ptSelStart, ptSelEnd); CPoint ptCursorPos; if (ptSelStart != ptSelEnd) { ptCursorPos = ptSelStart; DeleteCurrentSelection(); } else { ptCursorPos = GetCursorPos(); if (m_bOvrMode && ptCursorPos.x < GetLineLength(ptCursorPos.y)) m_pTextBuffer->DeleteText(this, ptCursorPos.y, ptCursorPos.x, ptCursorPos.y, ptCursorPos.x + 1, CE_ACTION_TYPING); // [JRT] } ASSERT_VALIDTEXTPOS(ptCursorPos); char pszText[2]; pszText[0] = (char) nChar; pszText[1] = 0; int x,y; USES_CONVERSION; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, A2T(pszText), y, x, CE_ACTION_TYPING); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); if(!bUndoBeginGroup) m_pTextBuffer->FlushUndoGroup(this); } } }
DWORD CCrystalTextView:: ParseLineSgml (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 (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 > 1 && pszChars[I] == '>' && pszChars[nPrevI] == '-' && *::CharPrev(pszChars, pszChars + nPrevI) == '-') { dwCookie &= ~COOKIE_EXT_COMMENT; bRedefineBlock = true; } continue; } // Extended comment <?....?> if (dwCookie & COOKIE_EXT_USER1) { if (I > 0 && pszChars[I] == '>' && pszChars[nPrevI] == '?') { dwCookie &= ~COOKIE_EXT_USER1; 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 (!(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; } 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 (dwCookie & COOKIE_PREPROCESSOR) { if (IsSgmlKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD); } else if (IsUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1); } else if (IsSgmlNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { goto next; } } else if (dwCookie & COOKIE_USER1) { if (IsUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2); } else { goto next; } } else if (IsSgmlNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } else { goto next; } bRedefineBlock = true; bDecIndex = true; nIdentBegin = -1; next: ; } // Preprocessor start: < or bracket if (!(dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '<' && !(I < nLength - 3 && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-') || pszChars[I] == '{') { DEFINE_BLOCK (I + 1, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; nIdentBegin = -1; continue; } // Preprocessor end: > or bracket if (dwCookie & COOKIE_PREPROCESSOR) { if (pszChars[I] == '>' || pszChars[I] == '}') { dwCookie &= ~COOKIE_PREPROCESSOR; nIdentBegin = -1; bRedefineBlock = true; bDecIndex = true; continue; } } // Preprocessor start: & if (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 (IsSgmlKeyword (pszChars + nIdentBegin, I - nIdentBegin)) { 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 (IsSgmlNumber (pszChars + nIdentBegin, I - nIdentBegin)) { DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER); } } // Preprocessor start: < or { if (!(dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '<' && !(I < nLength - 3 && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-') || pszChars[I] == '{') { DEFINE_BLOCK (I + 1, COLORINDEX_PREPROCESSOR); dwCookie |= COOKIE_PREPROCESSOR; nIdentBegin = -1; goto end; } // Preprocessor end: > or } if (dwCookie & COOKIE_PREPROCESSOR) { if (pszChars[I] == '>' || pszChars[I] == '}') { dwCookie &= ~COOKIE_PREPROCESSOR; nIdentBegin = -1; } } end: dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_STRING | COOKIE_PREPROCESSOR | COOKIE_EXT_USER1); return dwCookie; }
void CCrystalEditView::OnEditReplace() { if (! QueryEditable()) return; CWinApp *pApp = AfxGetApp(); ASSERT(pApp != NULL); CEditReplaceDlg dlg(this); // Take search parameters from registry dlg.m_bMatchCase = pApp->GetProfileInt(REG_REPLACE_SUBKEY, REG_MATCH_CASE, FALSE); dlg.m_bWholeWord = pApp->GetProfileInt(REG_REPLACE_SUBKEY, REG_WHOLE_WORD, FALSE); dlg.m_sText = pApp->GetProfileString(REG_REPLACE_SUBKEY, REG_FIND_WHAT, _T("")); dlg.m_sNewText = pApp->GetProfileString(REG_REPLACE_SUBKEY, REG_REPLACE_WITH, _T("")); /* if (IsSelection()) { GetSelection(m_ptSavedSelStart, m_ptSavedSelEnd); m_bSelectionPushed = TRUE; dlg.m_nScope = 0; // Replace in current selection dlg.m_ptCurrentPos = m_ptSavedSelStart; dlg.m_bEnableScopeSelection = TRUE; dlg.m_ptBlockBegin = m_ptSavedSelStart; dlg.m_ptBlockEnd = m_ptSavedSelEnd; } else { dlg.m_nScope = 1; // Replace in whole text dlg.m_ptCurrentPos = GetCursorPos(); dlg.m_bEnableScopeSelection = FALSE; }*/ // Take the current selection, if any if (IsSelection()) { CPoint ptSelStart, ptSelEnd; GetSelection(ptSelStart, ptSelEnd); if (ptSelStart.y == ptSelEnd.y) { LPCTSTR pszChars = GetLineChars(ptSelStart.y); int nChars = ptSelEnd.x - ptSelStart.x; lstrcpyn(dlg.m_sText.GetBuffer(nChars + 1), pszChars + ptSelStart.x, nChars + 1); dlg.m_sText.ReleaseBuffer(); } dlg.m_nScope = 1; // Replace in whole text dlg.m_ptCurrentPos = ptSelStart; dlg.m_bEnableScopeSelection = FALSE; } // Execute Replace dialog m_bShowInactiveSelection = TRUE; dlg.DoModal(); m_bShowInactiveSelection = FALSE; // Restore selection if (m_bSelectionPushed) { SetSelection(m_ptSavedSelStart, m_ptSavedSelEnd); m_bSelectionPushed = FALSE; } // Save search parameters to registry pApp->WriteProfileInt(REG_REPLACE_SUBKEY, REG_MATCH_CASE, dlg.m_bMatchCase); pApp->WriteProfileInt(REG_REPLACE_SUBKEY, REG_WHOLE_WORD, dlg.m_bWholeWord); pApp->WriteProfileString(REG_REPLACE_SUBKEY, REG_FIND_WHAT, dlg.m_sText); pApp->WriteProfileString(REG_REPLACE_SUBKEY, REG_REPLACE_WITH, dlg.m_sNewText); }
void CScriptStreamLimiter::GetMoreData(int &nChar, int &nLine, int &nLength, PCSTR &pszLine) { while (nChar > nLength) { // Need to move to the next line int cLines = GetLineCount(); bool fAtLimitedEnd = true; while (nLine < cLines) { nLine++; if (nLine < cLines) { fAtLimitedEnd = false; // Indicate this definitely isn't a limited end. nLength = GetLineLength(nLine); pszLine = GetLineChars(nLine); ASSERT(pszLine != NULL); nChar = 0; break; // done } } if (nLine == cLines) { bool fGenerateEOF = true; // We ran out of data. if (fAtLimitedEnd) { if (_hACDone && !_fCancel) { fGenerateEOF = false; // We're at a "limited end". Let's tell the client and block. SetEvent(_hACDone); // Tell the client // Wait for future instructions if (WAIT_OBJECT_0 == WaitForSingleObject(_hDoAC, INFINITE)) { fGenerateEOF = _fCancel; if (!_fCancel) { nLine--; // 1) Pretend we're back where we were when we entered. // nLength should be unchanged, nLine should be --, nChar should be unchanged. // We should refetch nLength (since it may have changed) (don't think we need a new pszLine???) pszLine = GetLineChars(nLine); // REVIEW: is this even necessary? nLength = GetLineLength(nLine); // And then go back to teh beginning of the top level loop. } } else { ASSERT(FALSE); } } else if (_pCallback) { _pCallback->Done(); } } if (fGenerateEOF) { pszLine = "\0"; // EOF nLength = 1; nChar = 0; } } // else we're all good. } }
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; }
void CEditWnd::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { CTextWnd::OnChar(nChar, nRepCnt, nFlags); if (m_bOemCharset) CharToOemBuff((char*)&nChar, (char*)&nChar, 1); if ((::GetAsyncKeyState(VK_LBUTTON) | ::GetAsyncKeyState(VK_RBUTTON)) & 0x8000) return; BOOL bTranslated = FALSE; if (nChar == VK_RETURN) { m_pTextBuffer->BeginUndoGroup(); if (QueryEditable() && m_pTextBuffer != NULL) { DeleteCurrentSelection(); CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); int x, y; CString pszText = "\r\n"; bool flag; if (ptCursorPos.x > 0) { LPCSTR chars1 = GetLineChars(ptCursorPos.y); char *p = 0; for (int j = 0; j < QUOTE_LENGTH && j < GetLineLength(ptCursorPos.y); j++) if (chars1[j] == '>') p = (char*)chars1 + j; flag = p != 0 && ptCursorPos.x < GetLineLength(ptCursorPos.y); //Вставим знаки квоты if (flag) { p++; while (isspace((unsigned char)*p)) p++; pszText += CString(chars1, (int)(p - chars1)); } //Автоотступ else if (m_bAutoIndent) { LPCSTR chars = m_pTextBuffer->GetLineChars(ptCursorPos.y); int len = m_pTextBuffer->GetLineLength(ptCursorPos.y); for (int j = 0; j < len && isspace((unsigned char)chars[j]); j++) pszText += chars[j]; } } else flag = false; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); ptCursorPos.x = flag ? 0 : x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); } m_pTextBuffer->FlushUndoGroup(this); return; } else if (nChar > 31) { if (QueryEditable() && m_pTextBuffer != NULL) { m_pTextBuffer->BeginUndoGroup(nChar != _T(' ')); CPoint ptSelStart, ptSelEnd; GetSelection(ptSelStart, ptSelEnd); CPoint ptCursorPos; if (ptSelStart != ptSelEnd) { ptCursorPos = ptSelStart; DeleteCurrentSelection(); } else ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); char pszText[2]; pszText[0] = (char) nChar; pszText[1] = 0; int x, y; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); m_pTextBuffer->FlushUndoGroup(this); } } }
void CEditWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { CTextWnd::OnKeyDown(nChar, nRepCnt, nFlags); if (!QueryEditable() || m_pTextBuffer == NULL) return; bool isShift = (GetKeyState(VK_SHIFT) & 0xF0) != 0; bool isCtrl = (GetKeyState(VK_CONTROL) & 0xF0) != 0; if (nChar == VK_TAB) { BOOL bTabify = FALSE; CPoint ptSelStart, ptSelEnd; if (IsSelection()) { GetSelection(ptSelStart, ptSelEnd); bTabify = ptSelStart.y != ptSelEnd.y; } if (bTabify) { m_pTextBuffer->BeginUndoGroup(); int nStartLine = ptSelStart.y; int nEndLine = ptSelEnd.y; ptSelStart.x = 0; if (ptSelEnd.x > 0) { if (ptSelEnd.y == GetLineCount() - 1) { ptSelEnd.x = GetLineLength(ptSelEnd.y); } else { ptSelEnd.x = 0; ptSelEnd.y ++; } } else nEndLine --; SetSelection(ptSelStart, ptSelEnd); SetCursorPos(ptSelEnd); EnsureVisible(ptSelEnd); // Shift selection to right m_bHorzScrollBarLocked = TRUE; //static const TCHAR pszText[] = _T("\t"); CString pszText; if (!m_bReplaceTabs) pszText = "\t"; else { CString tmp(' ', GetTabSize()); pszText = tmp; } for (int L = nStartLine; L <= nEndLine; L ++) { int x, y; m_pTextBuffer->InsertText(this, L, 0, pszText, y, x, CE_ACTION_INDENT); } m_bHorzScrollBarLocked = FALSE; RecalcHorzScrollBar(); m_pTextBuffer->FlushUndoGroup(this); } else { m_pTextBuffer->BeginUndoGroup(); DeleteCurrentSelection(); CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); CString pszText; if (!m_bReplaceTabs) pszText = "\t"; else { CString tmp(' ', GetTabSize()); pszText = tmp; } int x, y; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); m_pTextBuffer->FlushUndoGroup(this); } } if (nChar == VK_BACK && !IsSelection()) { CPoint ptCursorPos = GetCursorPos(); if (ptCursorPos.y > 0 || (ptCursorPos.x > 0 && ptCursorPos.y == 0)) { CPoint ptCurrentCursorPos = ptCursorPos; bool bDeleted = false; if(ptCursorPos.x == 0) { ptCursorPos.y--; ptCursorPos.x = GetLineLength(ptCursorPos.y); bDeleted = true; } else { ptCursorPos.x--; bDeleted = true; } ASSERT_VALIDTEXTPOS(ptCursorPos); SetAnchor(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); if (bDeleted) m_pTextBuffer->DeleteText(this, ptCursorPos.y, ptCursorPos.x, ptCurrentCursorPos.y, ptCurrentCursorPos.x, CE_ACTION_BACKSPACE); } } if (nChar == VK_DELETE && !isShift) { CPoint ptSelStart, ptSelEnd; GetSelection(ptSelStart, ptSelEnd); if (ptSelStart == ptSelEnd) { if (ptSelEnd.x == GetLineLength(ptSelEnd.y)) { if (ptSelEnd.y == GetLineCount() - 1) return; ptSelEnd.y++; ptSelEnd.x = 0; if (GetLineLength(ptSelStart.y) != 0) { LPCSTR chars = GetLineChars(ptSelEnd.y); for (int j = 0; j < QUOTE_LENGTH && j < GetLineLength(ptSelEnd.y); j++) if (chars[j] == '>') ptSelEnd.x = j + 1; while (ptSelEnd.x < GetLineLength(ptSelEnd.y) && (chars[ptSelEnd.x] == ' ' || chars[ptSelEnd.x] == '\t')) ptSelEnd.x++; } } else ptSelEnd.x++; } CPoint ptCursorPos = ptSelStart; ASSERT_VALIDTEXTPOS(ptCursorPos); SetAnchor(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); m_pTextBuffer->DeleteText(this, ptSelStart.y, ptSelStart.x, ptSelEnd.y, ptSelEnd.x, CE_ACTION_DELETE); } if ((nChar == 'X' && isCtrl) || (nChar == VK_DELETE && isShift)) Cut(); if ((nChar == 'V' && isCtrl) || (nChar == VK_INSERT && isShift)) Paste(); if (nChar == 'Z' && isCtrl && isShift) Redo(); if (nChar == 'Z' && isCtrl && !isShift) Undo(); }
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; }