gstStatus gstTXTTable::Open(gstReadMode read_mode) {
  read_mode_ = read_mode;

  //
  // get the stat structure of this file to make a few guesses
  //
  if (!khExists(name())) {
    notify(NFY_WARN, "Text file \"%s\" doesn't appear to exist", name());
    return GST_OPEN_FAIL;
  }

  if ((file_descriptor_ = ::open64(name(), O_RDONLY | O_NONBLOCK)) == -1) {
    notify(NFY_WARN, "Unable to open txt file %s", name());
    return GST_OPEN_FAIL;
  }

  //
  // try to use existing index file, otherwise build a new one
  //
  if (LoadIndex() != GST_OKAY && BuildIndex() != GST_OKAY) {
    notify(NFY_WARN, "Unable to build index of txt file %s", name());
    ::close(file_descriptor_);
    file_descriptor_ = -1;
    return status_;
  }

  return (status_ = GST_OKAY);
}
示例#2
0
 BaiIndexedBamReaderPrivate(const BamFile& file,
                            const GenomicInterval& interval)
     : htsIndex_(nullptr)
     , htsIterator_(nullptr)
 {
     LoadIndex(file.Filename());
     Interval(file.Header(), interval);
 }
示例#3
0
// Set up poetry filenames, preferences, load the index
// Load index (or compile it if none found)
void TryLoadIndex()
{
    index_ok = (LoadIndex(index_filename) != 0);
    if (!index_ok || (nitems == 0))
    {
        PoetryError(wxT("Index file not found; will compile new one"), wxT("wxPoem"));
        index_ok = Compile();
    }
}
示例#4
0
size_t BlockHashIndex::Load(std::FILE * mphf)
{
  size_t byteSize = LoadIndex(mphf);
  size_t end = std::ftell(mphf);
  
  for(size_t i = 0; i < m_seekIndex.size(); i++)
      LoadRange(i);
  std::fseek(m_fileHandle, end, SEEK_SET);
  return byteSize;
}
示例#5
0
XZIP_Resource::XZIP_Resource(char* fname,int fl)
{
	int sz;
	flags = fl;

	fileName = strdup(fname);
	idxName = strdup(fname);
	sz = strlen(fname);
	idxName[sz - 1] = 'x';
	idxName[sz - 2] = 'd';
	idxName[sz - 3] = 'i';

	file.open(fname,XS_IN);
	if(flags & XZIP_ENABLE_ZIP_HEADERS)
		LoadHeaders();
	else 
		LoadIndex();
}
void FPakFile::Initialize(FArchive* Reader)
{
	if (Reader->TotalSize() < Info.GetSerializedSize())
	{
		UE_LOG(LogPakFile, Fatal, TEXT("Corrupted pak file (too short)."));
	}
	else
	{
		// Serialize trailer and check if everything is as expected.
		Reader->Seek(Reader->TotalSize() - Info.GetSerializedSize());
		Info.Serialize(*Reader);
		check(Info.Magic == FPakInfo::PakFile_Magic);
		check(Info.Version >= FPakInfo::PakFile_Version_Initial && Info.Version <= FPakInfo::PakFile_Version_Latest);

		LoadIndex(Reader);
		// LoadIndex should crash in case of an error, so just assume everything is ok if we got here.
		bIsValid = true;
	}	
}
示例#7
0
Index::Index(std::string Name, std::string tableName, index_t indextype,tindex_t tindextype)
{
this->IndexName=Name;
this->TableName=tableName;
this->IndexType=indextype;
this->tIndexType=tindextype;
this->IndexPrimario="=";
this->typeIndexPrimario=FNULL;
ifstream file(GetFileName(this->IndexName,this->TableName).c_str());
  if (file.is_open())
  {
     file.close();
     LoadIndex();
  }  
  else 
  {
      SaveIndex();
  }
                   
}
bool
CResArchive::LoadArchive( const VFS::CString& archiveName ,
                          const VFS::CString& archivePath ,
                          const bool writableRequest      )
{GUCEF_TRACE;

    // We do not support writable archives
    if ( writableRequest ) return false;

    // Since we always need both the index file and the resource file
    // already construct the paths for both

    CORE::CString fileExt = CORE::ExtractFileExtention( archivePath ).Uppercase();
    if ( fileExt.IsNULLOrEmpty() )
    {
        m_idxPath = m_resPath = archivePath;
        m_idxPath += ".IDX";
        m_resPath += ".RES";
    }
    else
    if ( fileExt.Equals( "RES", false ) )
    {
        m_resPath = archivePath;
        m_idxPath = archivePath.CutChars( 4, false, 0 ) + ".IDX";
    }
    else
    if ( fileExt.Equals( "IDX", false ) )
    {
        m_idxPath = archivePath;
        m_resPath = archivePath.CutChars( 4, false, 0 ) + ".RES";
    }

    m_archiveName = archiveName;
    m_archivePath = archivePath;

    return LoadIndex();
}
示例#9
0
int HDRecordFileReader::DoReadRecordFile()
{
    unsigned char buf[RECORD_BUF_LEN] = "";
    long filesize = 0;
    /*
    FILE* fp;
    if((fp = ACE_OS::fdopen(_file_handler,"rb")) == NULL)
    {
    	ACE_DEBUG((LM_ERROR,"打开文件流失败!"));
    	return -1;
    }
    */
    //if((filesize = ACE_OS::fseek(fp,0L,SEEK_END)) == -1 )
    if((filesize = ACE_OS::lseek(_file_handler,0L,SEEK_END)) == -1 )
    {
        ACE_DEBUG((LM_ERROR,"取得文件大小失败"));
        return -1;
    }
    // 大小为空的文件,要删除
    if(filesize == 0)
    {
        ACE_DEBUG((LM_DEBUG,"空记录文件,自动删除.."));
        return 0;
    }

    // 文件大小不对
    if(filesize % RECORD_BUF_LEN != 0)
    {
        ACE_DEBUG((LM_ERROR,"流水记录文件大小不正确!"));
        return -2;
    }
    size_t reccnt = filesize / sizeof(buf);
    size_t index = LoadIndex();
    // 认为读取完
    if(index >= reccnt)
        return 0;
#if 1
    if(index > 0)
        ACE_DEBUG((LM_DEBUG,"重新分析记录文件index[%d]",index));
#endif
    //if(ACE_OS::fseek(fp,sizeof(buf)*index,SEEK_SET) == -1)
    if(ACE_OS::lseek(_file_handler,sizeof(buf)*index,SEEK_SET) == -1)
    {
        ACE_DEBUG((LM_ERROR,"定位记录失败!"));
        return -1;
    }
    size_t readbytes = 0;
    size_t bufsize = 0;
    do
    {
        //readbytes = ACE_OS::fread(buf+bufsize,sizeof(buf) - bufsize,1,fp);
        readbytes = ACE_OS::read(_file_handler,buf+bufsize,sizeof(buf) - bufsize);
        if(readbytes == 0)
        {
            if(bufsize == sizeof buf)
            {
                // 一条流水
                ACE_DEBUG((LM_DEBUG,"正在处理最后一条记录[%d]...",index));
                if(SavePosRecord(buf))
                    return -1;
                SaveIndex(++index);
            }
            return 0;
        }
        bufsize += readbytes;
        if(bufsize == sizeof buf)
        {
            // 一条流水
            ACE_DEBUG((LM_DEBUG,"正在处理记录[%d]...",index));
            if(SavePosRecord(buf))
                return -1;
            SaveIndex(++index);
            bufsize = 0;
        }
        //KSGThreadUtil::Sleep(1000);
    } while(1);
    return 0;
}
示例#10
0
文件: ana.cpp 项目: nealey/vera
//----------------------------------------------------------------------
int ana(void)
{
  CIC_param ctype;
  register segment_t *s = getMySeg(cmd.ea); // also set curSeg

  if ( s->type != SEG_CODE || cmd.ip >= curSeg.CodeSize ) {
    warning("Can't decode non-code fragment!");
    return(0);
  }

  cmd.Op1.dtyp = dt_void;
  cmd.wid = cmd.swit = 0;
  cmd.Op1.ref = 0;

  if ( (cmd.itype = ua_next_byte()) == j_wide ) {
    if(   (cmd.itype = ua_next_byte()) == j_iinc
       || (cmd.itype >= j_iload && cmd.itype <= j_aload)
       || (cmd.itype >= j_istore && cmd.itype <= j_astore)
       || cmd.itype == j_ret) cmd.wid = 1; //_w
    else {
      if ( !debugmode) return(0 );
      cmd.size = 1;
      cmd.itype = j_wide;
    }
  }

  if ( cmd.itype >= j_lastnorm ) {
    if ( !debugmode) return(0 );
    if ( cmd.itype < j_quick_last ) {
      static const uchar redefcmd[j_quick_last - j_lastnorm] = {
            j_ldc,                    //j_ldc_quick
            j_ldcw,                   //j_ldcw_quick
            j_ldc2w,                  //j_ldc2w_quick
            j_getfield,               //j_getfield_quick
            j_putfield,               //j_putfield_quick
            j_getfield,               //j_getfield2_quick
            j_putfield,               //j_putfield2_quick
            j_getstatic,              //j_getstatic_quick
            j_putstatic,              //j_putstatic_quick
            j_getstatic,              //j_getstatic2_quick
            j_putstatic,              //j_putstatic2_quick
            j_invokevirtual,          //j_invokevirtual_quick
            j_invokespecial,          //j_invokenonvirtual_quick
            j_a_invokesuper,          //j_invokesuper_quick
            j_invokestatic,           //j_invokestatic_quick
            j_invokeinterface,        //j_invokeinterface_quick
            j_a_invokevirtualobject,  //j_invokevirtualobject_quick
            j_a_invokeignored,        //j_invokeignored_quick
            j_new,                    //j_new_quick
            j_anewarray,              //j_anewarray_quick
            j_multianewarray,         //j_multianewarray_quick
            j_checkcast,              //j_checkcast_quick
            j_instanceof,             //j_instanceof_quick
            j_invokevirtual,          //j_invokevirtual_quick_w
            j_getfield,               //j_getfield_quick_w
            j_putfield                //j_putfield_quick_w
        };

      cmd.wid = 2; //_quick;
      switch ( cmd.itype ) {
        case j_getstatic2_quick:
        case j_putstatic2_quick:
        case j_getfield2_quick:
        case j_putfield2_quick:
          cmd.wid = 3;  //2_quick
          break;
        case j_invokevirtual_quick_w:
        case j_getfield_quick_w:
        case j_putfield_quick_w:
          cmd.wid = 4;  //_quick_w
          break;
        default:
          break;
      }
      cmd.itype = redefcmd[cmd.itype - j_lastnorm];
    } else if ( cmd.itype < j_software) return(0 );
           else cmd.itype -= (j_software - j_a_software);
  }
//---
  switch ( cmd.itype ) {
    default:
      {
        register unsigned refs, ref2f;

        if ( cmd.itype >= j_iload_0 && cmd.itype <= j_aload_3 ) {
          refs = (cmd.itype - j_iload_0) % 4;
          ref2f = (cmd.itype - j_iload_0) / 4;
          ref2f =   ref2f == ((j_lload_0 - j_iload_0) / 4)
                 || ref2f == ((j_dload_0 - j_iload_0) / 4);
          goto refer;
        }
        if ( cmd.itype >= j_istore_0 && cmd.itype <= j_astore_3 ) {
          refs = (cmd.itype - j_istore_0) % 4;
          ref2f = (cmd.itype - j_istore_0) / 4;
          ref2f =    ref2f == ((j_lstore_0 - j_istore_0) / 4)
                  || ref2f == ((j_dstore_0 - j_istore_0) / 4);
refer:
          cmd.Op1.addr = curSeg.DataBase + (ushort)refs;
          cmd.Op1.ref = (uchar)(ref2f + 1);
          if ( (ushort)(refs + ref2f) >= curSeg.DataSize ) cmd.Op1.ref |= 0x80;
          break;
        }
      } // end refs/refx
      if ( cmd.itype < j_ifeq || cmd.itype > j_jsr ) break;
    case j_ifnull:
    case j_ifnonnull:
      cmd.Op1.addr = (short)ua_next_word();
b_near:
      cmd.Op1.type = o_near;
      cmd.Op1.offb = 1;
      cmd.Op1.addr += cmd.ip;
      if ( cmd.Op1.addr >= curSeg.CodeSize ) goto set_bad_ref;
      break;

    case j_goto_w:
    case j_jsr_w:
      cmd.Op1.addr = ua_next_long();
      goto b_near;

    case j_bipush:
      cmd.Op1.dtyp = dt_byte;
      cmd.Op1.value = (char)ua_next_byte();
      goto setdat;
    case j_sipush:
      cmd.Op1.dtyp = dt_word;
      cmd.Op1.value = (short)ua_next_word();
setdat:
      cmd.Op1.type = o_imm;
      cmd.Op1.offb = 1;
      break;

    case j_ldc:
      cmd.Op1.cp_ind = ua_next_byte();
      ctype = C_4byte;
      goto constchk;
    case j_ldcw:
      ctype = C_4byte;
      goto const2w;
    case j_ldc2w:
      ctype = C_8byte;
const2w:
      cmd.Op1.cp_ind = ua_next_word();
constchk:
      if ( !ConstLoad(ctype)) return(0 );
      break;

    case j_getstatic:
    case j_putstatic:
    case j_getfield:
    case j_putfield:
      if ( cmd.wid > 1 ) {     //_quick form
        cmd.Op1.type = o_imm;
        cmd.Op1.ref = 2;        //#data
        cmd.Op1.offb = 1;
        if ( cmd.wid == 4 ) { //???
          cmd.Op1.dtyp = dt_word;
          cmd.Op1.value = ua_next_word();
        } else {
          cmd.Op1.dtyp = dt_byte;
          cmd.Op1.value = ua_next_byte();
          ++cmd.size;           // SKIP
        }
        break;
      }
      ctype = C_Field;
      goto const2w;

    case j_new:
      ctype = C_Class;
      goto const2w;

    case j_anewarray:
//\\ ?/
    case j_checkcast:
    case j_instanceof:
      ctype = C_TypeName;
      goto const2w;

    case j_a_invokesuper:
    case j_a_invokeignored:
      goto fictarg;
    case j_invokevirtual:
    case j_a_invokevirtualobject:
      cmd.Op2.dtyp = dt_void;
      if ( cmd.wid > 1 ) {
        if ( cmd.wid == 4 ) {
fictarg:
          cmd.Op1.value = ua_next_word(); //???
          cmd.Op1.dtyp = dt_word;
        } else {
          cmd.Op2.type = o_imm;
          cmd.Op1.ref = 2;        //#data
          cmd.Op1.dtyp = cmd.Op2.dtyp = dt_byte;
          cmd.Op1.value = ua_next_byte();
          cmd.Op2.offb = 2;
          cmd.Op2.value = ua_next_byte();
        }
        cmd.Op1.offb = 1;
        cmd.Op1.type = o_imm;
        cmd.Op1.ref = 2;        //#data
        break;
      }
    case j_invokespecial:
    case j_invokestatic:
    case j_invokedynamic:
      ctype = C_Method;
      goto const2w;
    case j_invokeinterface:
      ctype = C_Interface;
      cmd.Op1.cp_ind = ua_next_word();
      cmd.Op2.type = o_imm;
      cmd.Op2.ref = 1;          //not descriptor
      cmd.Op2.dtyp = dt_byte;
      cmd.Op2.value = ua_next_byte();
      if ( cmd.wid > 1 ) {
        cmd.Op3.type = o_imm;
        cmd.Op3.ref = 2;        //#data
        cmd.Op3.value = ua_next_byte();
        cmd.Op3.offb = 4;
        cmd.Op3.dtyp = dt_byte;
      } else {
        ++cmd.size;  //reserved
        cmd.Op3.dtyp = dt_void;
      }
      goto constchk;

    case j_multianewarray:
      cmd.Op1.cp_ind = ua_next_word();
      cmd.Op2.type = o_imm;
      cmd.Op2.ref = 1;         // not descriptor
      cmd.Op2.dtyp = dt_byte;
      if ( (cmd.Op2.value = ua_next_byte()) == 0 && !debugmode) return(0 );
      ctype = C_Type;
      goto constchk;

    case j_iinc:
    case j_iload:
    case j_istore:
      cmd.Op1.dtyp = dt_dword;
      goto memref;
    case j_lload:
    case j_lstore:
      cmd.Op1.dtyp = dt_qword;
      goto memref;
    case j_fload:
    case j_fstore:
      cmd.Op1.dtyp = dt_float;
      goto memref;
    case j_dload:
    case j_dstore:
      cmd.Op1.dtyp = dt_double;
      goto memref;
    case j_aload:
    case j_astore:
      cmd.Op1.dtyp = dt_string;
      goto memref;
    case j_ret:
      cmd.Op1.dtyp = dt_code;
memref:
      if ( !LoadIndex()) return(0 );
      if ( cmd.itype == j_iinc ) {
        cmd.Op2.type = o_imm;
        cmd.Op2.ref = 0;
        cmd.Op2.offb = (uchar)cmd.size;
//\\??? Это надо???
        if ( cmd.wid ) {
          cmd.Op2.dtyp = dt_word;
          cmd.Op2.value = (short)ua_next_word();
        } else {
          cmd.Op2.dtyp = dt_byte;
          cmd.Op2.value = (char)ua_next_byte();
        }
      }
      break;

    case j_tableswitch:
    case j_lookupswitch:
      {
        int32 count;
        register uint32 top;

        cmd.swit = 1;
        for(top = (4  - uint32((cmd.ip + cmd.size) % 4)) & 3; top; top--)
          if ( ua_next_byte() ) {
            if ( !debugmode) return(0 );
            cmd.swit |= 0100;
          }
        cmd.Op3.type = o_near;
        cmd.Op3.offb = (uchar)cmd.size;
        cmd.Op3.addr = ua_next_long();
        cmd.Op3.addr += cmd.ip;
        cmd.Op3.ref = 0;

        if ( cmd.Op3.addr >= curSeg.CodeSize ) {
          if ( !debugmode) return(0 );
          ++cmd.Op3.ref;
        }

        cmd.swit |= 2;  // start out arguments

        count = ua_next_long();
        if ( cmd.itype == j_tableswitch ) {
          cmd.Op1.type  = o_imm;
          cmd.Op1.dtyp  = dt_dword;
          cmd.Op1.value = count;  // minimal value
          cmd.Op2.ref   = 0;
          cmd.Op2.type  = o_imm;
          cmd.Op2.dtyp  = dt_dword;
          count = (uint32(cmd.Op2.value = ua_next_long()) - count + 1);
        }
        cmd.Op3.value = count;
        cmd.Op2.addr = cmd.ip + cmd.size;
        top = uint32(curSeg.CodeSize - cmd.ip);
        while ( count-- ) {
          if ( cmd.itype == j_lookupswitch) ua_next_long( ); // skip pairs;
          if ( (cmd.ip + ua_next_long()) >= curSeg.CodeSize ) {
            if ( !debugmode) return(0 );
            cmd.swit |= 0200;
          }
          if ( (uint32)cmd.size >= top) return(0 );
        }
      }
      break;

    case j_newarray:
      cmd.Op1.type = o_array;       // type!
      cmd.Op1.offb = 1;
      if(   (cmd.Op1.cp_type = ua_next_byte()) < T_BOOLEAN
         || (uchar)cmd.Op1.cp_type > T_LONG) {
set_bad_ref:
        if ( !debugmode) return(0 );
        ++cmd.Op1.ref;
      }
      break;
  } // switch ( cmd.itype )

  return(cmd.size);
}
示例#11
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;
}