void
collectAllCatalogKeys(BString& inputStr)
{
	RegExp rx;
	struct regexp *rxprg = rx.Compile(rxString.String());
	if (rx.InitCheck() != B_OK) {
		fprintf(stderr, "regex-compilation error %s\n", rx.ErrorString());
		return;
	}
	status_t res;
	const char *in = inputStr.String();
	while (rx.RunMatcher(rxprg, in)) {
		const char *start = rxprg->startp[0];
		in = rxprg->endp[0];
		if (fetchKey(in)) {
			if (haveID) {
				if (showKeys)
					printf("CatKey(%ld)\n", id);
				res = catalog->SetString(id, "");
				if (res != B_OK) {
					fprintf(stderr, "couldn't add key %ld - error: %s\n",
						id, strerror(res));
					exit(-1);
				}
			} else {
				if (showKeys) {
					printf("CatKey(\"%s\", \"%s\", \"%s\")\n", str.String(),
						ctx.String(), cmt.String());
				}
				res = catalog->SetString(str.String(), str.String(),
					ctx.String(), cmt.String());
				if (res != B_OK) {
					fprintf(stderr, "couldn't add key %s,%s,%s - error: %s\n",
						str.String(), ctx.String(), cmt.String(),
						strerror(res));
					exit(-1);
				}
			}
		} else if (showWarnings) {
			const char *end = strchr(in, ';');
			BString match;
			if (end)
				match.SetTo(start, end-start+1);
			else {
				// can't determine end of statement, we output next 40 chars
				match.SetTo(start, 40);
			}
			fprintf(stderr, "Warning: couldn't resolve catalog-access:\n\t%s\n",
				match.String());
		}
	}
}
예제 #2
0
파일: strmix.cpp 프로젝트: CyberShadow/FAR
bool SearchString(const string& Source, const string& Str, string& ReplaceStr,int& CurPos, int Position,int Case,int WholeWords,int Reverse,int Regexp, int *SearchLength,const wchar_t* WordDiv)
{
	int StrSize=StrLength(Source);
	*SearchLength = 0;

	if (!WordDiv)
		WordDiv=Global->Opt->strWordDiv;

	if (Reverse)
	{
		Position--;

		if (Position>=StrSize)
			Position=StrSize-1;

		if (Position<0)
			return false;
	}

	if ((Position<StrSize || (!Position && !StrSize)) && !Str.IsEmpty())
	{
		if (Regexp)
		{
			string strSlash(Str);
			InsertRegexpQuote(strSlash);
			RegExp re;
			// Q: что важнее: опция диалога или опция RegExp`а?
			if (!re.Compile(strSlash, OP_PERLSTYLE|OP_OPTIMIZE|(!Case?OP_IGNORECASE:0)))
				return false;

			SMatch m[10*2], *pm = m;
			intptr_t n = re.GetBracketsCount();
			if (n > static_cast<int>(ARRAYSIZE(m)/2))
			{
				pm = (SMatch *)xf_malloc(2*n*sizeof(SMatch));
				if (!pm)
					return false;
			}

			bool found = false;
			int half = 0;
			if (!Reverse)
			{
				if (re.SearchEx(Source,Source+Position,Source+StrSize,pm,n))
					found = true;
			}
			else
			{
				int pos = 0;
				for (;;)
				{
					if (!re.SearchEx(Source,Source+pos,Source+StrSize,pm+half,n))
						break;
					pos = static_cast<int>(pm[half].start);
					if (pos > Position)
						break;

					found = true;
					++pos;
					half = n - half;
				}
				half = n - half;
			}
			if (found)
			{
				*SearchLength = pm[half].end - pm[half].start;
				CurPos = pm[half].start;
				ReplaceStr=ReplaceBrackets(Source,ReplaceStr,pm+half,n);
			}
			if (pm != m)
				xf_free(pm);

			return found;
		}

		if (Position==StrSize)
			return false;

		int Length = *SearchLength = (int)Str.GetLength();

		for (int I=Position; (Reverse && I>=0) || (!Reverse && I<StrSize); Reverse ? I--:I++)
		{
			for (int J=0;; J++)
			{
				if (!Str[J])
				{
					CurPos=I;
					return true;
				}

				if (WholeWords)
				{
					int locResultLeft=FALSE;
					int locResultRight=FALSE;
					wchar_t ChLeft=Source[I-1];

					if (I>0)
						locResultLeft=(IsSpace(ChLeft) || wcschr(WordDiv,ChLeft));
					else
						locResultLeft=TRUE;

					if (I+Length<StrSize)
					{
						wchar_t ChRight=Source[I+Length];
						locResultRight=(IsSpace(ChRight) || wcschr(WordDiv,ChRight));
					}
					else
					{
						locResultRight=TRUE;
					}

					if (!locResultLeft || !locResultRight)
						break;
				}

				wchar_t Ch=Source[I+J];

				if (Case)
				{
					if (Ch!=Str[J])
						break;
				}
				else
				{
					if (Upper(Ch)!=Upper(Str[J]))
						break;
				}
			}
		}
	}

	return false;
}
예제 #3
0
static void NavigateTo(TagInfo* info)
{
  DWORD ver=I.AdvControl(I.ModuleNumber,ACTL_GETFARVERSION,NULL);
  int build=(ver&0xffff0000)>>16;
  EditorInfo ei;
  I.EditorControl(ECTL_GETINFO,&ei);
  {
    SUndoInfo ui;
    ui.file=ei.FileName;
    ui.line=ei.CurLine;
    ui.pos=ei.CurPos;
    ui.top=ei.TopScreenLine;
    ui.left=ei.LeftPos;
    UndoArray.Push(ui);
  }
  WindowInfo wi;
  int ok=0;

  const char* file=info->file.Str();
  if(build>1500)
  {
    int c=I.AdvControl(I.ModuleNumber,ACTL_GETWINDOWCOUNT,NULL);
    for(int i=0;i<c;i++)
    {
      wi.Pos=i;
      I.AdvControl(I.ModuleNumber,ACTL_GETWINDOWINFO,(void*)&wi);
      if(wi.Type==WTYPE_EDITOR && !lstrcmpi(wi.Name,file))
      {
        I.AdvControl(I.ModuleNumber,ACTL_SETCURRENTWINDOW,(void*)i);
        //if(mode==MODE_EDITOR)I.AdvControl(I.ModuleNumber,ACTL_COMMIT,(void*)i);
        I.AdvControl(I.ModuleNumber,ACTL_COMMIT,(void*)i);
        ok=1;
        break;
      }
    }
  }
  int havere=info->re.Length()>0;
  RegExp re;
  if(havere)re.Compile(info->re);
  if(!ok)
  {
    FILE *f=fopen(file,"rt");
    if(!f)
    {
      Msg(MEFailedToOpen);
      return;
    }
    int line=info->lineno-1;
    int cnt=0;
    char buf[512];
    while(fgets(buf,sizeof(buf),f) && cnt<line)cnt++;
    chomp(buf);
    SMatch m[10];
    int n=10;
    if(line!=-1)
    {
      if(havere && !re.Match(buf,m,n))
      {
        line=-1;
//        Msg("not found in place, searching");
      }
    }
    if(line==-1)
    {
      if(!havere)
      {
        NotFound(file,info->lineno);
        fclose(f);
        return;
      }
      line=0;
      fseek(f,0,SEEK_SET);
      while(fgets(buf,sizeof(buf),f))
      {
        chomp(buf);
        n=10;
        if(re.Match(buf,m,n))
        {
          break;
        }
        line++;
      }
      if(feof(f))
      {
        NotFound(file,info->lineno);
        fclose(f);
        return;
      }
    }
    fclose(f);
    I.Editor(file,"",0,0,-1,-1,build>1500?EF_NONMODAL:0,line+1,1);
    return;
  }
  EditorSetPosition esp;
  I.EditorControl(ECTL_GETINFO,&ei);

  esp.CurPos=-1;
  esp.CurTabPos=-1;
  esp.TopScreenLine=-1;
  esp.LeftPos=-1;
  esp.Overtype=-1;


  int line=info->lineno-1;
  if(line!=-1)
  {
    EditorGetString egs;
    egs.StringNumber=line;
    I.EditorControl(ECTL_GETSTRING,&egs);
    SMatch m[10];
    int n=10;

    if(havere && !re.Match(egs.StringText,egs.StringText+egs.StringLength,m,n))
    {
      line=-1;
    }
  }
  if(line==-1)
  {
    if(!havere)
    {
      esp.CurLine=ei.CurLine;
      esp.TopScreenLine=ei.TopScreenLine;
      I.EditorControl(ECTL_SETPOSITION,&esp);
      NotFound(file,info->lineno);
      return;
    }
    line=0;
    SMatch m[10];
    int n=10;
    EditorGetString egs;
    while(line<ei.TotalLines)
    {
      esp.CurLine=line;
      I.EditorControl(ECTL_SETPOSITION,&esp);
      egs.StringNumber=-1;
      I.EditorControl(ECTL_GETSTRING,&egs);
      n=10;
      if(re.Match(egs.StringText,egs.StringText+egs.StringLength,m,n))
      {
        break;
      }
      line++;
    }
    if(line==ei.TotalLines)
    {
      esp.CurLine=info->lineno==-1?ei.CurLine:info->lineno-1;
      esp.TopScreenLine=ei.TopScreenLine;
      I.EditorControl(ECTL_SETPOSITION,&esp);
      NotFound(file,info->lineno);
      return;
    }
  }

  esp.CurLine=line;
  esp.TopScreenLine=esp.CurLine-1;
  if(esp.TopScreenLine==-1)esp.TopScreenLine=0;
  if(ei.TotalLines<ei.WindowSizeY)esp.TopScreenLine=0;
  esp.LeftPos=0;
  I.EditorControl(ECTL_SETPOSITION,&esp);
  I.EditorControl(ECTL_REDRAW,NULL);
}