int EBuffer::MoveWordOrCapEndRight() { PELine L = VLine(CP.Row); int C, P; C = CP.Col; P = CharOffset(L, C); if (P >= L->Count) return 0; while ((P < L->Count) && (WGETBIT(Flags.WordChars, L->Chars[P]) == 0)) P++; while ((P < L->Count) && (WGETBIT(Flags.CapitalChars, L->Chars[P]) == 1)) P++; while ((P < L->Count) && (WGETBIT(Flags.WordChars, L->Chars[P]) == 1) && (WGETBIT(Flags.CapitalChars, L->Chars[P]) == 0)) P++; C = ScreenPos(L, P); return SetPos(C, CP.Row); }
int EBuffer::MoveWordRightX(int start) { PELine L = VLine(CP.Row); int C, P; int wS = start, wE = 1 - start; C = CP.Col; P = CharOffset(L, C); if (P >= L->Count) return 0; while ((P < L->Count) && (WGETBIT(Flags.WordChars, L->Chars[P]) == wS)) P++; while ((P < L->Count) && (WGETBIT(Flags.WordChars, L->Chars[P]) == wE)) P++; C = ScreenPos(L, P); return SetPos(C, CP.Row); }
int EBuffer::MoveWordLeftX(int start) { if (CP.Col > 0) { int wS = start, wE = 1 - start; PELine L = VLine(CP.Row); int C, P; C = CP.Col; P = CharOffset(L, C); if (P > L->Count) P = L->Count; if (P > 0) { while ((P > 0) && (WGETBIT(Flags.WordChars, L->Chars[P - 1]) == wE)) P--; while ((P > 0) && (WGETBIT(Flags.WordChars, L->Chars[P - 1]) == wS)) P--; C = ScreenPos(L, P); return SetPos(C, CP.Row); } else return 0; } else return 0; }
int EBuffer::MoveWordOrCapEndLeft() { if (CP.Col > 0) { PELine L = VLine(CP.Row); int C, P; C = CP.Col; P = CharOffset(L, C); if (P > L->Count) P = L->Count; if (P > 0) { while ((P > 0) && (WGETBIT(Flags.WordChars, L->Chars[P - 1]) == 1) && (WGETBIT(Flags.CapitalChars, L->Chars[P - 1]) == 0)) P--; while ((P > 0) && (WGETBIT(Flags.CapitalChars, L->Chars[P - 1]) == 1)) P--; while ((P > 0) && (WGETBIT(Flags.WordChars, L->Chars[P - 1]) == 0)) P--; C = ScreenPos(L, P); return SetPos(C, CP.Row); } else return 0; } else return 0; }
int EBuffer::KillWordOrCap() { int Y = VToR(CP.Row); if (CP.Col >= LineLen()) { if (KillChar() == 0) return 0; } else { PELine L = VLine(CP.Row); int P = CharOffset(L, CP.Col); int C; int Class = ChClassK(L->Chars[P]); if (Class == 1) { if (WGETBIT(Flags.CapitalChars, L->Chars[P]) == 1) while ((P < L->Count) && (WGETBIT(Flags.CapitalChars, L->Chars[P]) == 1)) P++; while ((P < L->Count) && (WGETBIT(Flags.WordChars, L->Chars[P]) == 1) && (WGETBIT(Flags.CapitalChars, L->Chars[P]) == 0)) P++; } else while ((P < L->Count) && (ChClassK(L->Chars[P]) == Class)) P++; C = ScreenPos(L, P); if (DelText(Y, CP.Col, C - CP.Col) == 0) return 0; } return 1; }
int EBuffer::KillWordOrCapPrev() { int Y = VToR(CP.Row); if (CP.Col == 0) { if (KillCharPrev() == 0) return 0; } else if (CP.Col > LineLen()) { if (SetPos(LineLen(), CP.Row) == 0) return 0; } else { PELine L = RLine(Y); int P = CharOffset(L, CP.Col); int C; int Class = ChClassK(L->Chars[P - 1]); if (Class == 1) { if (WGETBIT(Flags.CapitalChars, L->Chars[P - 1]) == 0) while ((P > 0) && (WGETBIT(Flags.WordChars, L->Chars[P - 1]) == 1) && (WGETBIT(Flags.CapitalChars, L->Chars[P - 1]) == 0)) P--; while ((P > 0) && (WGETBIT(Flags.CapitalChars, L->Chars[P - 1]) == 1)) P--; } else while ((P > 0) && (ChClassK(L->Chars[P - 1]) == Class)) P--; C = ScreenPos(L, P); if (DelText(Y, C, CP.Col - C) == 0) return 0; if (SetPos(C, CP.Row) == 0) return 0; } return 1; }
int Hilit_SIMPLE(EBuffer *BF, int LN, PCell B, int Pos, int Width, ELine *Line, hlState& State, hsState *StateMap, int *ECol) { EColorize *col = BF->Mode->fColorize; HMachine *hm = col->hm; HILIT_VARS(col->Colors, Line); HState *st = 0; HTrans *tr = 0; int t, cc; int quotech = 0; int matchFlags; int matchLen; int nextState; char *match; int lastPos = -1; hlState entryState; int iterCount; bool reportError = true; if ((hm == 0) || (hm->stateCount == 0)) return 0; if (State >= hm->stateCount) State = 0; st = hm->state + State; Color = st->color; /*{ fprintf(stderr, "ColMode:%s, State:%d\n", col->Name, State); for (int s = 0; s < hm->stateCount; s++) { fprintf(stderr, "State:%d, transCount:%d, firstTrans:%d, options:%d, color:%d, nextState:%d\n", s, hm->state[s].transCount, hm->state[s].firstTrans, hm->state[s].options, hm->state[s].color, hm->state[s].nextState); } for (int t = 0; t < hm->transCount; t++) { fprintf(stderr, "Trans:%d, matchLen:%d, matchFlags:%d, nextState:%d, color:%d\n", t, hm->trans[t].matchLen, hm->trans[t].matchFlags, hm->trans[t].nextState, hm->trans[t].color); } //exit(1); sleep(5); }*/ for (i = 0; i < Line->Count;) { // Check for infinite loops if (i == lastPos) { if (++iterCount > hm->stateCount) { // Passed the same position more times than number of states -> must be // looping if (reportError) { // Report only once per line since other errors may be false alarms // caused by hiliter restart reportError = false; BF->Msg(S_INFO, "Hiliter looping at line %d, column %d, entry state %d", LN + 1, i + 1, entryState); } else { // Already reported - advance by one character Color = hm->state[entryState].color; IF_TAB() else ColorNext(); } // Restart with state 0 State = 0; st = hm->state; iterCount = 1; goto next_state; } } else { lastPos = i; entryState = State; iterCount = 1; } if (quotech) { quotech = 0; } else { for (t = 0; t < st->transCount; t++) { tr = hm->trans + st->firstTrans + t; matchLen = tr->matchLen; matchFlags = tr->matchFlags; match = tr->match; nextState = tr->nextState; // fprintf(stderr, // "line:%d, char:%d (%c), len:%d, state:%d, tr:%d, // st->transCount:%d, st->firstTrans:%d, nextState:%d, // matchFlags:%08x\n", // LN, i, *p, len, State, t, st->transCount, st->firstTrans, // nextState, matchFlags); if (len < matchLen) continue; if ((i > 0) && (matchFlags & MATCH_MUST_BOL)) continue; if ((matchFlags & (MATCH_SET | MATCH_NOTSET)) == 0) { if (matchFlags & MATCH_REGEXP) { RxMatchRes b; if (!RxExecMatch(tr->regexp, Line->Chars, Line->Count, p, &b, (matchFlags & MATCH_NO_CASE) ? 0 : RX_CASE)) continue; if ((b.Open[1] != -1) && (b.Close[1] != -1)) matchLen = b.Open[1] - i; else matchLen = b.Close[0] - i; } else if (matchFlags & MATCH_NO_CASE) { if (memicmp(match, p, matchLen)) continue; } else { for (cc = 0; cc < matchLen; cc++) if (p[cc] != match[cc]) goto next_trans; } } else if (matchFlags & MATCH_SET) { if (!WGETBIT(match, *p)) continue; } else if (matchFlags & MATCH_NOTSET) { if (WGETBIT(match, *p)) continue; } if ((len != matchLen) && (matchFlags & MATCH_MUST_EOL)) continue; if (matchFlags & MATCH_NOGRAB) { State = nextState; if (State >= hm->stateCount) State = 0; st = hm->state + State; // fprintf(stderr, "nograb\n"); } else { if (matchFlags & MATCH_TAGASNEXT) { State = nextState; if (State >= hm->stateCount) State = 0; st = hm->state + State; } Color = tr->color; for (cc = 0; cc < matchLen; cc++) IF_TAB() else ColorNext(); if (!(matchFlags & MATCH_TAGASNEXT)) { State = nextState; if (State >= hm->stateCount) State = 0; st = hm->state + State; } if (len > 0) { if (matchFlags & MATCH_QUOTECH) quotech = 1; } else if (len == 0) { if (matchFlags & MATCH_QUOTEEOL) goto end_parse; /* see note below !! */ } } // fprintf(stderr, "next state\n"); goto next_state; next_trans: /* */ ; } if (st->wordChars != 0) { int j; hlState MState = State; j = 0; while (((i + j) < Line->Count) && (WGETBIT(st->wordChars, Line->Chars[i + j]))) j++; // GP (fix) Color = st->color; if (j == 0) { if (st->nextKwdNoCharState != -1) { State = st->nextKwdNoCharState; if (State >= hm->stateCount) State = 0; st = hm->state + State; Color = st->color; goto next_state; } } else { if (st->GetHilitWord(j, &Line->Chars[i], Color) || BF->GetHilitWord(j, &Line->Chars[i], Color, BFI(BF, BFI_MatchCase) ? 0 : 1)) { if (st->nextKwdMatchedState != -1) State = st->nextKwdMatchedState; } else { if (st->nextKwdNotMatchedState != -1) { State = st->nextKwdNotMatchedState; if (st->options & STATE_NOGRAB) { if (State >= hm->stateCount) State = 0; st = hm->state + State; Color = st->color; goto next_state; } } } if (State >= hm->stateCount) State = 0; // highlight/tag as next state if (st->options & STATE_TAGASNEXT) { MState = State; st = hm->state + State; Color = st->color; } if (StateMap) memset(StateMap + i, MState, j); if (B) MoveMem(B, C - Pos, Width, Line->Chars + i, HILIT_CLRD(), j); i += j; len -= j; p += j; C += j; if (!(st->options & STATE_TAGASNEXT)) { st = hm->state + State; Color = st->color; } goto next_state; } } } Color = st->color; IF_TAB() else ColorNext(); next_state: /* */ ; }
int EBuffer::FindStr(const char *Data, int Len, SearchReplaceOptions &opt) { int Options = opt.Options; int LLen, Start, End; int C, L; PELine X; char *P; if (Options & SEARCH_RE) return 0; if (Len <= 0) return 0; if (Options & SEARCH_NOPOS) { C = Match.Col; L = Match.Row; } else { C = CP.Col; L = VToR(CP.Row); } if (Match.Row != -1) Draw(Match.Row, Match.Row); Match.Row = -1; Match.Col = -1; X = RLine(L); C = CharOffset(X, C); if (Options & SEARCH_NEXT) { int CC = MatchCount ? 1 : 0; if (Options & SEARCH_BACK) { C -= CC; if (C < 0) { if (L == 0) return 0; L--; X = RLine(L); C = X->Count; } } else { if (Options & SEARCH_REPLACE && opt.lastInsertLen > 0) { C += CC * opt.lastInsertLen; // 0 or opt.lastInsertLen } else { C += CC; } if (C >= X->Count) { C = 0; L++; if (L == RCount) return 0; } } } MatchLen = 0; MatchCount = 0; if (Options & SEARCH_BLOCK) { if (Options & SEARCH_BACK) { if (BlockMode == bmStream) { if (L > BE.Row) { L = BE.Row; C = BE.Col; } if (L == BE.Row && C > BE.Col) C = BE.Col; } else { if (L >= BE.Row && BE.Row > 0) { L = BE.Row - 1; C = RLine(L)->Count; } if (BlockMode == bmColumn) if (L == BE.Row - 1 && C >= BE.Col) C = BE.Col; } } else { if (L < BB.Row) { L = BB.Row; C = 0; } if (L == BB.Row && C < BB.Col) C = BB.Col; } } while (1) { if (Options & SEARCH_BLOCK) { if (BlockMode == bmStream) { if (L > BE.Row || L < BB.Row) break; } else if (L >= BE.Row || L < BB.Row) break; } else if (L >= RCount || L < 0) break; X = RLine(L); LLen = X->Count; P = X->Chars; Start = 0; End = LLen; if (Options & SEARCH_BLOCK) { if (BlockMode == bmColumn) { Start = CharOffset(X, BB.Col); End = CharOffset(X, BE.Col); } else if (BlockMode == bmStream) { if (L == BB.Row) Start = CharOffset(X, BB.Col); if (L == BE.Row) End = CharOffset(X, BE.Col); } } if (Options & SEARCH_BACK) { if (C >= End - Len) C = End - Len; } else { if (C < Start) C = Start; } while (((!(Options & SEARCH_BACK)) && (C <= End - Len)) || ((Options & SEARCH_BACK) && (C >= Start))) { if ((!(Options & SEARCH_WORDBEG) || (C == 0) || (WGETBIT(Flags.WordChars, P[C - 1]) == 0)) && (!(Options & SEARCH_WORDEND) || (C + Len >= End) || (WGETBIT(Flags.WordChars, P[C + Len]) == 0)) && ((!(Options & SEARCH_NCASE) && (P[C] == Data[0]) && (memcmp(P + C, Data, Len) == 0)) || ((Options & SEARCH_NCASE) && (toupper(P[C]) == toupper(Data[0])) && (strnicmp(P + C, Data, Len) == 0))) /* && BOL | EOL */ ) { Match.Col = ScreenPos(X, C); Match.Row = L; MatchCount = Len; MatchLen = ScreenPos(X, C + Len) - Match.Col; if (!(Options & SEARCH_NOPOS)) { if (Options & SEARCH_CENTER) CenterPosR(Match.Col, Match.Row); else SetPosR(Match.Col, Match.Row); } Draw(L, L); return 1; } if (Options & SEARCH_BACK) C--; else C++; } if (Options & SEARCH_BACK) { L--; if (L >= 0) C = RLine(L)->Count; } else { C = 0; L++; } } //SetPos(OC, OL); return 0; }
int Hilit_SIMPLE(EBuffer *BF, int /*LN*/, PCell B, int Pos, int Width, ELine *Line, hlState &State, hsState *StateMap, int *ECol) { EColorize *col = BF->Mode->fColorize; HMachine *hm = col->hm; HILIT_VARS(col->Colors, Line); HState *st = 0; HTrans *tr = 0; int t, cc; int quotech = 0; int matchFlags; int matchLen; int nextState; char *match; if (hm == 0 || hm->stateCount == 0) return 0; if (State >= hm->stateCount) State = 0; st = hm->state + State; Color = st->color; /*{ fprintf(stderr, "ColMode:%s, State:%d\n", col->Name, State); for (int s = 0; s < hm->stateCount; s++) { fprintf(stderr, "State:%d, transCount:%d, firstTrans:%d, options:%d, color:%d, nextState:%d\n", s, hm->state[s].transCount, hm->state[s].firstTrans, hm->state[s].options, hm->state[s].color, hm->state[s].nextState); } for (int t = 0; t < hm->transCount; t++) { fprintf(stderr, "Trans:%d, matchLen:%d, matchFlags:%d, nextState:%d, color:%d\n", t, hm->trans[t].matchLen, hm->trans[t].matchFlags, hm->trans[t].nextState, hm->trans[t].color); } //exit(1); sleep(5); }*/ for (i = 0; i < Line->Count; ) { if (quotech) { quotech = 0; } else { for (t = 0; t < st->transCount; t++) { tr = hm->trans + st->firstTrans + t; matchLen = tr->matchLen; matchFlags = tr->matchFlags; match = tr->match; nextState = tr->nextState; //fprintf(stderr, // "line:%d, char:%d (%c), len:%d, state:%d, tr:%d, st->transCount:%d, st->firstTrans:%d, nextState:%d, matchFlags:%08x\n", // LN, i, *p, len, State, t, st->transCount, st->firstTrans, nextState, matchFlags); if (len < matchLen) continue; if ((i > 0) && (matchFlags & MATCH_MUST_BOL)) continue; if ((matchFlags & (MATCH_SET | MATCH_NOTSET)) == 0) { if (matchFlags & MATCH_REGEXP) { RxMatchRes b; if (!RxExecMatch(tr->regexp, Line->Chars, Line->Count, p, &b, (matchFlags & MATCH_NO_CASE) ? 0 : RX_CASE)) continue; if (b.Open[1] != -1 && b.Close[1] != -1) matchLen = b.Open[1] - i; else matchLen = b.Close[0] - i; } else if (matchFlags & MATCH_NO_CASE) { if (memicmp(match, p, matchLen)) continue; } else { for (cc = 0; cc < matchLen; cc++) if (p[cc] != match[cc]) goto next_trans; } } else if (matchFlags & MATCH_SET) { if (!WGETBIT(match, *p)) continue; } else if (matchFlags & MATCH_NOTSET) { if (WGETBIT(match, *p)) continue; } if ((len != matchLen) && (matchFlags & MATCH_MUST_EOL)) continue; if (matchFlags & MATCH_NOGRAB) { State = nextState; if (State >= hm->stateCount) State = 0; st = hm->state + State; //fprintf(stderr, "nograb\n"); } else { if (matchFlags & MATCH_TAGASNEXT) { State = nextState; if (State >= hm->stateCount) State = 0; st = hm->state + State; } Color = tr->color; for (cc = 0; cc < matchLen; cc++) IF_TAB() else ColorNext(); if (!(matchFlags & MATCH_TAGASNEXT)) { State = nextState; if (State >= hm->stateCount) State = 0; st = hm->state + State; } if (len > 0) { if (matchFlags & MATCH_QUOTECH) quotech = 1; } else if (len == 0) { if (matchFlags & MATCH_QUOTEEOL) goto end_parse; /* see note below !! */ } } //fprintf(stderr, "next state\n"); goto next_state; next_trans: /* */; } if (st->wordChars != 0) { int j; hlState MState = State; j = 0; while (((i + j) < Line->Count) && (WGETBIT(st->wordChars, Line->Chars[i + j]))) j++; //GP (fix) Color = st->color; if (j == 0) { if (st->nextKwdNoCharState != -1) { State = st->nextKwdNoCharState; if (State >= hm->stateCount) State = 0; st = hm->state + State; Color = st->color; goto next_state; } } else { if (st->GetHilitWord(j, &Line->Chars[i], Color ) || BF->GetHilitWord(j, &Line->Chars[i], Color, BFI( BF, BFI_MatchCase ) ? 0 : 1)) { if (st->nextKwdMatchedState != -1) State = st->nextKwdMatchedState; } else { if (st->nextKwdNotMatchedState != -1) { State = st->nextKwdNotMatchedState; if (st->options & STATE_NOGRAB) { if (State >= hm->stateCount) State = 0; st = hm->state + State; Color = st->color; goto next_state; } } } if (State >= hm->stateCount) State = 0; // highlight/tag as next state if (st->options & STATE_TAGASNEXT) { MState = State; st = hm->state + State; Color = st->color; } if (StateMap) memset(StateMap + i, MState, j); if (B) MoveMem(B, C - Pos, Width, Line->Chars + i, HILIT_CLRD(), j); i += j; len -= j; p += j; C += j; if (!(st->options & STATE_TAGASNEXT)) { st = hm->state + State; Color = st->color; } goto next_state; } } } Color = st->color; IF_TAB() else ColorNext(); next_state: /* */; } /* check if there are any matches for EOL */ /* NOTE: this is skipped when Q option is used above. !! */ for (t = 0; t < st->transCount; t++) { tr = hm->trans + st->firstTrans + t; matchLen = tr->matchLen; matchFlags = tr->matchFlags; match = tr->match; nextState = tr->nextState; if (((i > 0) && (matchFlags & MATCH_MUST_BOL)) || (matchFlags & MATCH_REGEXP)) continue; //cant match eol beyond eol. //if ((len != matchLen) && (matchFlags & MATCH_MUST_EOL)) //continue; if (matchLen == 0) { State = nextState; if (State >= hm->stateCount) State = 0; break; } } end_parse: ; *ECol = C; return 0; }