示例#1
0
int EBuffer::MoveFunctionNext() {
    int line = FindFunction(+1, +1);

    if (line == -1)
        return 0;

    return CenterPosR(0, line);
}
示例#2
0
int EBuffer::MoveFunctionPrev() {
    int line = FindFunction(-1, -1);

    if (line == -1)
        return 0;

    return CenterPosR(0, line);
}
示例#3
0
int EBuffer::FindRx(RxNode *Rx, SearchReplaceOptions &opt) {
    int Options = opt.Options;
    int LLen, Start, End;
    int C, L;
    char *P;
    PELine X;
    RxMatchRes b;

    if (!(Options & SEARCH_RE))
        return 0;
    if (Options & SEARCH_BACK) { // not supported
        View->MView->Win->Choice(GPC_ERROR, "FindRx", 1, "O&K", "Reverse regexp search not supported.");
        return 0;
    }
    if (Rx == 0)
        return 0;

    if (Match.Row != -1)
        Draw(Match.Row, Match.Row);
    Match.Row = -1;
    Match.Col = -1;

    C = CP.Col;
    L = VToR(CP.Row);
    X = RLine(L);
    C = CharOffset(X, C);

    if (Options & SEARCH_NEXT) {
        int CC = MatchCount ? MatchCount : 1;

        if (Options & SEARCH_BACK) {
            C -= CC;
            if (Options & SEARCH_BLOCK) {
                if (C < BB.Col && L == BB.Row)
                    return 0;
                L--;
                X = RLine(L);
                C = X->Count;
                if (BlockMode == bmColumn)
                    if (BE.Col < C)
                        C = BE.Col;
            } else {
                if (C < 0 && L == 0)
                    return 0;
                L--;
                X = RLine(L);
                C = X->Count;
            }
        } else {
            C += CC;
            if (Options & SEARCH_BLOCK) {
                if (BlockMode == bmStream || BlockMode == bmLine) {
                    if (C >= X->Count) {
                        C = 0;
                        L++;
                        if (BlockMode == bmLine) {
                            if (L == BE.Row) return 0;
                        } else
                            if (L == BE.Row && (C >= BE.Col || C >= X->Count))
                                return 0;
                    }
                } else if (BlockMode == bmColumn) {
                    if (C >= X->Count || C >= BE.Col) {
                        C = BB.Col;
                        L++;
                        if (L == BE.Row) return 0;
                    }
                }
            } else {
                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 (End > LLen)
                End = LLen;
        }
        if (Options & SEARCH_BACK) {
            if (C >= End)
                C = End;
        } else {
            if (C < Start)
                C = Start;
        }

        if (Start <= End) {
            if (RxExec(Rx, P + Start, End - Start, P + C, &b, (Options & SEARCH_NCASE) ? 0 : RX_CASE) == 1) {
                C = ScreenPos(X, b.Open[0] + Start);
                Match.Col = C;
                Match.Row = L;
                MatchCount = b.Close[0] - b.Open[0];
                MatchLen = ScreenPos(X, b.Close[0] + Start) - C;
                for (int mm = 0; mm < NSEXPS; mm++) {
                    b.Open[mm] += Start;
                    b.Close[mm] += Start;
                }
                MatchRes = b;
                if (!(Options & SEARCH_NOPOS)) {
                    if (Options & SEARCH_CENTER)
                        CenterPosR(C, L);
                    else
                        SetPosR(C, L);
                }
                Draw(L, L);
                return 1;
            }
        }
        C = 0;
        L++;
    }
    //SetPos(OC, OL);
    return 0;

}
示例#4
0
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;
}