示例#1
0
// FindFunction -- search for line matching 'RoutineRegexp'
// starting from current line + 'delta'. 'way' should be +1 or -1.
int EBuffer::FindFunction(int delta, int way) {
    RxNode     *regx;
    int         line;
    PELine      L;
    RxMatchRes  res;

    if (BFS(this, BFS_RoutineRegexp) == 0) {
        View->MView->Win->Choice(GPC_ERROR, "Error", 1,
                                 "O&K", "No routine regexp.");
        return -1;
    }
    regx = RxCompile(BFS(this, BFS_RoutineRegexp));
    if (regx == 0) {
        View->MView->Win->Choice(GPC_ERROR, "Error", 1,
                                 "O&K", "Failed to compile regexp '%s'",
                                 BFS(this, BFS_RoutineRegexp));
        return -1;
    }

    //** Scan backwards from the current cursor position,
    Msg(S_BUSY, "Matching %s", BFS(this, BFS_RoutineRegexp));
    line = VToR(CP.Row) + delta;
    while (line >= 0 && line < RCount) {
        L = RLine(line);
        if (RxExec(regx, L->Chars, L->Count, L->Chars, &res) == 1)
            break;
        line += way;
    }
    if (line < 0)
        line = 0;
    if (line >= RCount)
        line = RCount - 1;
    RxFree(regx);
    return line;
}
示例#2
0
int EBuffer::FoldCreateByRegexp(const char *Regexp) { /*FOLD00*/
  RxNode *R;
  int     err = 1;

  if (Modify() == 0) return 0;

  R = RxCompile(Regexp);

  if (R != NULL) {
    PELine X;
    int    first = -1;
    int    L;

    for (L = 0; L < RCount; L++) {
      RxMatchRes RM;

      X = RLine(L);

      if (RxExec(R, X->Chars, X->Count, X->Chars, &RM) == 1) {
        if (first >= 0) {
          int i;

          for (i = L; i > 0; i--) {
            PELine Y;

            Y = RLine(i);

            if ((Y->Count == 0) || strrchr(Y->Chars, '}')) {
              if ((L - i) > 2) {
                while ((i > 0) && (RLine(i - 1)->Count == 0)) i--;

                if ((first >= 0) && i
                    && (FoldCreate(i) == 0)) err = 0;
              }
              break;
            }
          }
        } else first = L;

        if (FoldCreate(L) == 0) {
          err = 0;
          break;
        }
      }
    }
    RxFree(R);
  }
  return err;
}
示例#3
0
void ESvnBase::NotifyPipe (int APipeId) {
    if (APipeId==PipeId) {
        char line[1024];
        RxMatchRes RM;
        int i;

        while (GetLine((char *)line, sizeof(line))) {
            int len=strlen (line);
            if (len>0&&line[len-1]=='\n') line[--len]=0;
            for (i=0;i<SvnIgnoreRegexpCount;i++)
                if (RxExec (SvnIgnoreRegexp[i],line,len,line,&RM)==1) break;
            if (i==SvnIgnoreRegexpCount) ParseLine (line,len);
        }
        if (!Running) {
            char s[30];

            sprintf (s,"[done, status=%d]",ReturnCode);
            AddLine (0,-1,s);
        }
    }
}
示例#4
0
int EBuffer::ScanForRoutines() {
    RxNode *regx;
    int line;
    PELine L;
    RxMatchRes res;

    if (BFS(this, BFS_RoutineRegexp) == 0) {
        View->MView->Win->Choice(GPC_ERROR, "Error", 1, "O&K", "No routine regexp.");
        return 0;
    }
    regx = RxCompile(BFS(this, BFS_RoutineRegexp));
    if (regx == 0) {
        View->MView->Win->Choice(GPC_ERROR, "Error", 1, "O&K", "Failed to compile regexp '%s'", BFS(this, BFS_RoutineRegexp));
        return 0;
    }

    if (rlst.Lines) {
        free(rlst.Lines);
        rlst.Lines = 0;
    }
    rlst.Lines = 0;
    rlst.Count = 0;

    Msg(S_BUSY, "Matching %s", BFS(this, BFS_RoutineRegexp));
    for (line = 0; line < RCount; line++) {
        L = RLine(line);
        if (RxExec(regx, L->Chars, L->Count, L->Chars, &res) == 1) {
            rlst.Count++;
            rlst.Lines = (int *) realloc((void *) rlst.Lines, sizeof(int) * (rlst.Count | 0x1F));
            rlst.Lines[rlst.Count - 1] = line;
            Msg(S_BUSY, "Routines: %d", rlst.Count);
        }
    }
    RxFree(regx);
    return 1;
}
示例#5
0
文件: s_util.cpp 项目: dmcbride/efte
int CompletePath(const char *Base, char *Match, int Count) {
    char Name[MAXPATH];
    const char *dirp;
    char *namep;
    int len, count = 0;
    char cname[MAXPATH];
    int hascname = 0;
    RxMatchRes RM;
    FileFind *ff;
    FileInfo *fi;
    int rc;

    if (strcmp(Base, "") == 0) {
        if (ExpandPath(".", Name, sizeof(Name)) != 0) return -1;
    } else {
        if (ExpandPath(Base, Name, sizeof(Name)) != 0) return -1;
    }
//    SlashDir(Name);
    dirp = Name;
    namep = SepRChr(Name);
    if (namep == Name) {
        dirp = SSLASH;
        namep = Name + 1;
    } else if (namep == NULL) {
        namep = Name;
        dirp = SDOT;
    } else {
        *namep = 0;
        namep++;
    }

    len = strlen(namep);
    strcpy(Match, dirp);
    SlashDir(Match);
    cname[0] = 0;

    ff = new FileFind(dirp, "*",
                      ffDIRECTORY | ffHIDDEN
#if defined(USE_DIRENT)
                      | ffFAST // for SPEED
#endif
                     );
    if (ff == 0)
        return 0;
    rc = ff->FindFirst(&fi);
    while (rc == 0) {
        const char *dname = fi->Name();

        // filter out unwanted files
        if ((strcmp(dname, ".") != 0) &&
                (strcmp(dname, "..") != 0) &&
                (!CompletionFilter || RxExec(CompletionFilter, dname, strlen(dname), dname, &RM) != 1)) {
            if ((
#if defined(UNIX)
                        strncmp
#else // os2, nt, ...
                        strnicmp
#endif
                        (namep, dname, len) == 0)
                    && (dname[0] != '.' || namep[0] == '.')) {
                count++;
                if (Count == count) {
                    Slash(Match, 1);
                    strcat(Match, dname);
                    if (
#if defined(USE_DIRENT) // for SPEED
                        IsDirectory(Match)
#else
                        fi->Type() == fiDIRECTORY
#endif
                    )
                        Slash(Match, 1);
                } else if (Count == -1) {

                    if (!hascname) {
                        strcpy(cname, dname);
                        hascname = 1;
                    } else {
                        int o = 0;
#ifdef UNIX
                        while (cname[o] && dname[o] && (cname[o] == dname[o])) o++;
#endif
#if defined(OS2) || defined(NT)
                        while (cname[o] && dname[o] && (toupper(cname[o]) == toupper(dname[o]))) o++;
#endif
                        cname[o] = 0;
                    }
                }
            }
        }
        delete fi;
        rc = ff->FindNext(&fi);
    }
    delete ff;
    if (Count == -1) {
        Slash(Match, 1);
        strcat(Match, cname);
        if (count == 1) SlashDir(Match);
    }
    return count;
}
示例#6
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;

}