Example #1
0
void GetFiles(StrList& dst)
{
  for(int i=0;i<files.Count();i++)
  {
    dst<<files[i]->filename;
  }
}
Example #2
0
void FindParts(const char* file, const char* part,StrList& dst)
{
  String filename=file;
  filename.ToLower();
  dst.Clean();
  StrList tmp;
  int i;
  for(i=0;i<files.Count();i++)
  {
    if(files[i]->mainaload ||
       files[i]->isLoadBase(filename))
    {
      FindPartsInFile(files[i],part,tmp);
    }
  }
  if(tmp.Count()==0)return;
  tmp.Sort(dst);
  i=1;
  String *s=&dst[0];
  while(i<dst.Count())
  {
    if(dst[i]==*s)
    {
      dst.Delete();
    }else
    {
      s=&dst[i];
      i++;
      if(i==dst.Count())break;
    }
  }
}
Example #3
0
PTagArray FindFileSymbols(const char* file)
{
  String filename=file;
  filename.ToLower();
  PTagArray ta=new TagArray;
  for(int i=0;i<files.Count();i++)
  {
    if(files[i]->mainaload ||
       files[i]->isLoadBase(filename))
    {
      int j=0;
      while(filename[j]==files[i]->filename[j])j++;
      while(filename[j-1]!='\\')j--;
      if(files[i]->filename.Index("\\",j)==-1)
      {
        FindFile(files[i],filename.Substr(j),ta);
        FindFile(files[i],filename,ta);
      }
    }
  }
  if(ta->Count()==0)
  {
    delete ta;
    ta=NULL;
  }
  return ta;
}
Example #4
0
int Count()
{
  int cnt=0;
  for(int i=0;i<files.Count();i++)
  {
    cnt+=files[i]->offsets.Count();
  }
  return cnt;
}
Example #5
0
int UpdateTagsFile(const char* file)
{
  TagFileInfo *fi=NULL;
  int i;
  String filename=file;
  filename.ToLower();
  for(i=0;i<files.Count();i++)
  {
    if(files[i]->filename==filename)
    {
      fi=files[i];
      break;
    }
  }
  if(!fi)
  {
    struct stat st;
    if(stat(filename,&st)==-1)return 0;
    TagFileInfo tfi;
    tfi.filename=filename;
    tfi.modtm=st.st_mtime;
    if(!FindIdx(&tfi))return 0;
    if(Load(filename,"")!=1)return 0;
  }
  StrList sl;
  if(!CheckChangedFiles(filename,sl))return 0;
  if(sl.Count()==0)return 1;
  sl.SaveToFile("tags.changes");
  String cmd=config.exe+" ";
  String opt=config.opt;
  opt.Replace("-R","");
  RegExp re("/\\*(\\.\\S*)?/");
  SMatch m[4];
  int n=4;
  while(re.Search(opt,m,n))
  {
    opt.Delete(m[0].start,m[0].end-m[0].start);
  }
  cmd+=opt;
  cmd+=" -f tags.update -L tags.changes";
  //extern int Msg(const char* err);
  //Msg(cmd);
  if(!Execute(cmd))
  {
    remove("tags.changes");
    return 0;
  }
  MergeFiles(file,"tags.update");
  remove("tags.changes");
  remove("tags.update");
  Load(file,"");
  return 1;
}
Example #6
0
void UnloadTags(int idx)
{
  if(idx==-1)
  {
    for(int i=0;i<files.Count();i++)
    {
      delete files[i];
    }
    files.Clean();
  }else
  {
    delete files[idx];
    files.Delete(idx);
  }
}
Example #7
0
int CheckChangedFiles(const char* filename,StrList& dst)
{
  String file=filename;
  file.ToLower();
  for(int i=0;i<files.Count();i++)
  {
    if(files[i]->filename==file && files[i]->indexFile.Length())
    {
      struct stat stf,sti;
      if(stat(file,&stf)==-1)return 0;
      if(stat(files[i]->indexFile,&sti)==-1)return 0;
      if(stf.st_mtime!=sti.st_mtime)return 0;
      CheckFiles(files[i],dst);
      return 1;
    }
  }
  return 0;
}
Example #8
0
PTagArray Find(const char* symbol,const char* file)
{
  PTagArray ta=new TagArray;
  String filename=file;
  filename.ToLower();
  for(int i=0;i<files.Count();i++)
  {
    if(files[i]->mainaload ||
       files[i]->isLoadBase(filename))
    {
      FindInFile(files[i],symbol,ta);
    }
  }
  if(ta->Count()==0)
  {
    delete ta;
    ta=NULL;
  }
  return ta;
}
Example #9
0
int Load(const char* _filename,const char *base,bool mainaload)
{
  String filename=_filename;
  struct stat st;
  filename.ToLower();
  if(stat(filename,&st)==-1)return MEFailedToOpen;
  TagFileInfo *fi=NULL;
  for(int i=0;i<files.Count();i++)
  {
    if(files[i]->filename==filename)
    {
      fi=files[i];
      break;
    }
  }
  if(!fi)
  {
    fi=new TagFileInfo;
    fi->filename=filename;
    fi->modtm=st.st_mtime;
    fi->mainaload=mainaload;
    fi->addToLoadBases(base);
    files.Push(fi);
  }else
  {
    fi->addToLoadBases(base);
    if(fi->modtm==st.st_mtime)
    {
      return 1;
    }
  }
  struct stat sti;
  if(fi->indexFile.Length()>0)
  {
    if(stat(fi->indexFile,&sti)!=-1 && sti.st_mtime==st.st_mtime)
    {
      LoadIndex(fi);
      return 1;
    }
  }else
  if(FindIdx(fi))
  {
    if(stat(fi->indexFile,&sti)!=-1 && sti.st_mtime==st.st_mtime)
    {
      LoadIndex(fi);
      return 1;
    }
  }
  if(fi->indexFile.Length()==0)
  {
    for(;;)
    {
      fi->indexFile=fi->filename;
      fi->indexFile+=".idx";
      FILE *f=fopen(fi->indexFile,"wb");
      if(f)
      {
        fclose(f);
        remove(fi->indexFile);
        break;
      }
      char idxdir[512];
      const char *dirs[]={"TAGS_INDEX","TEMP","TMP",NULL};
      const char **dir=dirs;
      for(;*dir;dir++)
      {
        if(GetEnvironmentVariable(*dir,idxdir,sizeof(idxdir)))
        {
          fi->indexFile=fi->filename+".idx";
          fi->indexFile.Replace('\\','_');
          fi->indexFile.Replace(':','_');
          if(idxdir[strlen(idxdir)-1]!='\\')
          {
            fi->indexFile.Insert(0,"\\");
          }
          fi->indexFile.Insert(0,idxdir);
          f=fopen(fi->indexFile,"wb");
          if(f)
          {
            fclose(f);
            remove(fi->indexFile);
            break;
          }
          fi->indexFile="";
        }
      }
      break;
    }
  }
  if(fi->indexFile.Length()==0)
  {
    return MFailedToWriteIndex;
  }
  fi->modtm=st.st_mtime;
  CreateIndex(fi);
  return 0;
}