JIndexRange JCovering ( const JIndexRange& r1, const JIndexRange& r2 ) { const JBoolean n1 = r1.IsNothing(); const JBoolean n2 = r2.IsNothing(); if (n1 && n2) { return JIndexRange(); } else if (n1) { return r2; } else if (n2) { return r1; } else { return JIndexRange( JMin(r1.first, r2.first), JMax((r1.IsEmpty() ? r1.first-1 : r1.last), (r2.IsEmpty() ? r2.first-1 : r2.last)) ); } }
void JVIKeyHandler::YankToEndOfLine ( const JBoolean del, const JBoolean ins ) { JTextEditor* te = GetTE(); JIndexRange r; r.first = te->GetInsertionIndex(); const JIndex line = te->GetLineForChar(r.first) + GetOperationCount() - 1; r.last = te->GetLineEnd(line); if (te->IndexValid(r.last) && te->GetText().GetCharacter(r.last) == '\n') { r.last--; } if (!r.IsEmpty()) { CutBuffer* buf = GetCutBuffer(cutbufPattern); buf->Set(te->GetText().GetSubstring(r), kJFalse); if (del) { te->SetSelection(r); te->DeleteSelection(); } if (ins) { SetMode(kTextEntryMode); } } }
JBoolean JParseURL ( const JCharacter* url, JString* protocol, JString* host, JIndex* port, JString* path ) { *path = url; JArray<JIndexRange> matchList; if (urlPattern.Match(url, &matchList)) { protocol->Set(url, matchList.GetElement(2)); host->Set(url, matchList.GetElement(3)); JIndexRange r = matchList.GetElement(4); if (!r.IsEmpty()) { const JString s(url, r); if (!s.ConvertToUInt(port)) { *port = 0; } } else { *port = 0; } r = matchList.GetElement(5); if (!r.IsEmpty()) { path->Set(url, r); } else { *path = "/"; } return kJTrue; } return kJFalse; }
void CBTCLStyler::StyleEmbeddedVariables ( const Token& token ) { emptyVariablePattern.SetSingleLine(); variablePattern.SetSingleLine(); const JString& text = GetText(); JFontStyle varStyle = GetTypeStyle(token.type - kWhitespace); varStyle.underlineCount++; if (varStyle == GetTypeStyle(kVariable - kWhitespace)) { varStyle.underlineCount++; } JFontStyle errStyle = GetTypeStyle(kError - kWhitespace); errStyle.underlineCount++; if (errStyle == GetTypeStyle(kVariable - kWhitespace)) { errStyle.underlineCount++; } JIndexRange r = token.range, r1, r2; while (!r.IsEmpty()) { const JCharacter c = text.GetCharacter(r.first); if (c == '\\') { r.first++; } else if (c == '$') { r1 = r - (r.first-1); if (emptyVariablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2)) { r2 += r.first-1; AdjustStyle(r2, errStyle); r.first = r2.last; } else if (variablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2)) { r2 += r.first-1; AdjustStyle(r2, varStyle); r.first = r2.last; } } r.first++; } }
void JExtractFileAndLine ( const JCharacter* str, JString* fileName, JIndex* startLineIndex, JIndex* endLineIndex ) { static JRegex lineIndexRegex(":([0-9]+)(-([0-9]+))?$"); *fileName = str; JArray<JIndexRange> matchList; if (lineIndexRegex.Match(*fileName, &matchList)) { JString s = fileName->GetSubstring(matchList.GetElement(2)); JBoolean ok = s.ConvertToUInt(startLineIndex); assert( ok ); const JIndexRange endRange = matchList.GetElement(4); if (endLineIndex != NULL && !endRange.IsEmpty()) { s = fileName->GetSubstring(endRange); ok = s.ConvertToUInt(endLineIndex); assert( ok ); } else if (endLineIndex != NULL) { *endLineIndex = *startLineIndex; } fileName->RemoveSubstring(matchList.GetElement(1)); } else { *startLineIndex = 0; if (endLineIndex != NULL) { *endLineIndex = 0; } } }
void CBHTMLStyler::StyleEmbeddedVariables ( const Token& token ) { emptyVariablePattern.SetSingleLine(); variablePattern.SetSingleLine(); const JString& text = GetText(); JFontStyle varStyle = GetTypeStyle(token.type - kWhitespace); varStyle.underlineCount++; if (varStyle == GetTypeStyle(kPHPVariable - kWhitespace)) { varStyle.underlineCount++; } JFontStyle errStyle = GetTypeStyle(kError - kWhitespace); errStyle.underlineCount++; if (errStyle == GetTypeStyle(kPHPVariable - kWhitespace)) { errStyle.underlineCount++; } JIndexRange r = token.range, r1, r2; while (!r.IsEmpty()) { const JCharacter c = text.GetCharacter(r.first); if (c == '\\') { r.first++; } else if (c == '$') { r1 = r - (r.first-1); if (emptyVariablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2)) { r2 += r.first-1; const JCharacter c1 = text.GetCharacter(r2.last); if (c1 != '}' && c1 != ']') { r2.last--; } AdjustStyle(r2, errStyle); r.first = r2.last; } else if (variablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2)) { r2 += r.first-1; if (r2.first > 1 && text.GetCharacter(r2.first-1) == '{') { r2.first--; } AdjustStyle(r2, varStyle); r.first = r2.last; } } else if (c == '{' && r.first < r.last - 1 && text.GetCharacter(r.first+1) == '$' && text.GetCharacter(r.first+2) == '}') { r1.SetFirstAndLength(r.first, 3); AdjustStyle(r1, errStyle); r.first = r1.last; } r.first++; } }
JBoolean JTEStyler::SetStyle ( const JIndexRange& range, const JFontStyle& style ) { assert( !range.IsEmpty() ); if (itsCheckRange.last < range.first) { // we are beyond the range where anything could have changed return kJFalse; } assert( range.first == itsTokenStart ); if (itsRedoAllFlag) { JFontID fid = itsDefFontID; if (!OnlyColorChanged(style, itsDefFontStyle)) { fid = itsFontMgr->GetFontID(itsFontName, itsFontSize, style); } itsStyles->AppendElements(JTextEditor::Font(fid, itsFontSize, style, itsDefFontAlign), range.GetLength()); } else if (range.last >= itsCheckRange.first) { JIndexRange fontRange; fontRange.SetFirstAndLength(itsTokenFirstInRun, itsStyles->GetRunLength(itsTokenRunIndex)); const JBoolean beyondCurrentRun = JNegate( fontRange.Contains(range) ); JTextEditor::Font f = itsStyles->GetRunData(itsTokenRunIndex); if (beyondCurrentRun || style != f.style) { // extend the check range if we slop over into another style run // (HTML: type '<' after 'x' in "x<!--<br><h3>text</h3>-->") // extend past end of run to insure that we keep going until we // find a correctly styled token if (beyondCurrentRun) { JIndex runIndex = itsTokenRunIndex; JIndex firstInRun = itsTokenFirstInRun; const JBoolean ok = itsStyles->FindRun(itsTokenStart, range.last, &runIndex, &firstInRun); ExtendCheckRange(firstInRun + itsStyles->GetRunLength(runIndex)); } // extend check range to next token since this token was not // correctly styled -- should only stop when find correctly // styled tokens else // style != f.style { ExtendCheckRange(range.last+1); } // update the styles if (!beyondCurrentRun && OnlyColorChanged(style, f.style)) { *itsRedrawRange += range; } else { *itsRecalcRange += range; } f.size = itsFontSize; f.style = style; if (OnlyColorChanged(style, itsDefFontStyle)) { f.id = itsDefFontID; } else { f.id = itsFontMgr->GetFontID(itsFontName, itsFontSize, style); } f.align = itsDefFontAlign; itsStyles->RemoveNextElements(range.first, range.GetLength(), &itsTokenRunIndex, &itsTokenFirstInRun); run_assert(itsStyles, range.first, itsTokenRunIndex, itsTokenFirstInRun); itsStyles->InsertElementsAtIndex(range.first, f, range.GetLength(), &itsTokenRunIndex, &itsTokenFirstInRun); run_assert(itsStyles, range.first, itsTokenRunIndex, itsTokenFirstInRun); } } itsTokenStart = range.last+1; if (!itsRedoAllFlag) { const JBoolean ok = itsStyles->FindRun(range.first, itsTokenStart, &itsTokenRunIndex, &itsTokenFirstInRun); assert( ok || range.last == itsText->GetLength() ); assert( range.last == itsText->GetLength() || check_run(itsStyles, itsTokenStart, itsTokenRunIndex, itsTokenFirstInRun) ); } return JConvertToBoolean( range.last < itsCheckRange.last ); }
void CBCompileDocument::AppendText ( const JString& origText ) { const JString* text = &origText; JBoolean deleteText = kJFalse; if (strchr(*text, kMultibyteMarker) != NULL) { JString* s = jnew JString(origText); assert( s != NULL ); text = s; deleteText = kJTrue; JSize length = s->GetLength(); for (JIndex i=1; i<=length; i++) { if (s->GetCharacter(i) == kMultibyteMarker && i <= length-2) { const unsigned char c1 = s->GetCharacter(i+1); const unsigned char c2 = s->GetCharacter(i+2); const JIndex u = (((unsigned int) (unsigned char) c1) << 8) | ((unsigned int) (unsigned char) c2); if (u == 32920 || u == 32921) { s->ReplaceSubstring(i, i+2, "'"); } else { std::cout << "jcc: AppendText: unicode: " << u << std::endl; s->ReplaceSubstring(i, i+2, "\x80"); } length -= 2; } } } const JBoolean isJavacError = javacOutputRegex.Match(*text); JIndexRange gccPrevLineRange, gccRange; const JBoolean isGCCError = JI2B(!isJavacError && gccErrorRegex.Match(*text, &gccRange)); JIndexRange flexRange; const JBoolean isFlexError = flexErrorRegex.Match(*text, &flexRange); JIndexRange bisonRange; const JBoolean isBisonError = bisonErrorRegex.Match(*text, &bisonRange); JIndexRange makeRange; const JBoolean isMakeError = JI2B( makeErrorRegex.Match(*text, &makeRange) && !text->EndsWith(makeIgnoreErrorStr) ); JArray<JIndexRange> absoftRangeList; const JBoolean isAbsoftError = absoftErrorRegex.Match(*text, &absoftRangeList); JArray<JIndexRange> maven2RangeList; const JBoolean isMaven2Error = maven2ErrorRegex.Match(*text, &maven2RangeList); JArray<JIndexRange> maven3RangeList; const JBoolean isMaven3Error = maven3ErrorRegex.Match(*text, &maven3RangeList); if (isGCCError && gccErrorRegex.Match(itsPrevLine, &gccPrevLineRange) && gccPrevLineRange == gccRange && JCompareMaxN(itsPrevLine, *text, gccRange.last, kJTrue)) { JString s = *text; s.RemoveSubstring(1, gccRange.last - 1); s.Prepend(" /"); // in front of 1 or 2 trailing newlines CBTextEditor* te = GetTextEditor(); te->SetCaretLocation(te->GetTextLength() - (theDoubleSpaceFlag ? 1 : 0)); te->Paste(s); } else if (!isJavacError && !isGCCError && gccErrorRegex.Match(itsPrevLine, &gccPrevLineRange) && text->BeginsWith(gccMultilinePrefix) && text->GetLength() > kGCCMultilinePrefixLength && !isspace(text->GetCharacter(kGCCMultilinePrefixLength+1))) { JString s = *text; s.RemoveSubstring(1, strlen(gccMultilinePrefix)); CBTextEditor* te = GetTextEditor(); te->SetCaretLocation(te->GetTextLength() - (theDoubleSpaceFlag ? 1 : 0)); te->Paste(s); } else { CBTextEditor* te = GetTextEditor(); const JIndex startIndex = te->GetTextLength() + 1; CBExecOutputDocument::AppendText(*text); if (theDoubleSpaceFlag) { te->Paste("\n"); } itsPrevLine = *text; // display file name in bold and activate Errors menu JIndexRange boldRange; if (isJavacError) { JArray<JIndexRange> javacMatchList; if (javacErrorRegex.Match(*text, &javacMatchList)) { const JIndexRange r = javacMatchList.GetElement(2); boldRange.Set(startIndex + r.first-1, startIndex + r.last-1); } } else if (isGCCError) { boldRange.Set(startIndex, startIndex + gccRange.first - 1); } else if (isFlexError) { boldRange.Set(startIndex+1, startIndex + flexRange.first); } else if (isBisonError) { boldRange.Set(startIndex+2, startIndex + bisonRange.first + 1); } else if (isMakeError) { boldRange.SetFirstAndLength(startIndex, text->GetLength()); } else if (isAbsoftError) { boldRange = absoftRangeList.GetElement(2); boldRange += startIndex-1; } else if (isMaven2Error) { boldRange = maven2RangeList.GetElement(2); boldRange += startIndex-1; } else if (isMaven3Error) { boldRange = maven3RangeList.GetElement(2); boldRange += startIndex-1; } if (!boldRange.IsEmpty()) { te->JTextEditor::SetFont(boldRange.first, boldRange.last, GetErrorFont(), kJTrue); if (!itsHasErrorsFlag) { itsHasErrorsFlag = kJTrue; itsErrorMenu->Activate(); JXWindow* window = GetWindow(); JString windowTitle = window->GetTitle(); windowTitle.SetCharacter(1, '!'); windowTitle.SetCharacter(2, '!'); windowTitle.SetCharacter(3, '!'); window->SetTitle(windowTitle); } } } if (deleteText) { jdelete text; } }
JBoolean CBCtagsUser::HasExuberantCtags() { if (itsHasExuberantCtagsFlag == kUntested) { itsHasExuberantCtagsFlag = kFailure; // this hack is required on Linux kernel 2.3.x (4/19/2000) j_sig_func* origHandler = signal(SIGCHLD, emptyHandler); pid_t pid; #if defined _J_SUNOS pid_t* ppid = NULL; #else pid_t* ppid = &pid; #endif int fromFD; JError err = JExecute(kCheckVersionCmd, ppid, kJIgnoreConnection, NULL, kJCreatePipe, &fromFD, kJTossOutput, NULL); if (err.OK()) { JString vers; JReadAll(fromFD, &vers); JArray<JIndexRange> matchList; if (versionPattern.Match(vers, &matchList)) { matchList.RemoveElement(1); const JSize count = matchList.GetElementCount(); JString s; for (JIndex i=1; i<=count; i++) { JUInt v = 0; const JIndexRange r = matchList.GetElement(i); if (!r.IsEmpty()) { s = vers.GetSubstring(r); while (!isdigit(s.GetFirstCharacter())) { s.RemoveSubstring(1, 1); } const JBoolean ok = s.ConvertToUInt(&v); assert( ok ); } if (v > kMinVersion[i-1] || (i == count && v == kMinVersion[i-1])) { itsHasExuberantCtagsFlag = kSuccess; break; } else if (v < kMinVersion[i-1]) { break; } } } } if (origHandler != SIG_ERR) { signal(SIGCHLD, origHandler); } } return JI2B( itsHasExuberantCtagsFlag == kSuccess ); }