예제 #1
0
/*
 * Read the PACK directory into memory.  The optional offset to the
 * start of the PACK file is given in "offset".  The number of files in
 * the directory is returned in *dirsize_r.
 */
PACKDirPtr ReadPACKDirectory(FILE *packfile, UInt32 offset, UInt16 *dirsize_r)
{
  PACKDirPtr dir;
  UInt32     pos, size;
  UInt16     max, i;

  *dirsize_r = 0;
  if (packfile == NULL)
    return NULL;
  if ((fseek(packfile, offset, SEEK_SET) < 0)
      || (ReadMagic(packfile) != FTYPE_PACK)
      || (ReadInt32(packfile, &pos) == FALSE)
      || (ReadInt32(packfile, &size) == FALSE)
      || (size == 0L)
      || (size / sizeof(struct PACKDirectory) > 65535L)
      || (fseek(packfile, offset + pos, SEEK_SET) < 0))
    return NULL;
  dir = (PACKDirPtr)__qmalloc(size);
  max = (UInt16)(size / sizeof(struct PACKDirectory));
  for (i = 0; i < max; i++)
    {
      if (ReadBytes(packfile, &dir[i], sizeof(struct PACKDirectory)) == FALSE)
	{
	  free(dir);
	  return NULL;
	}
      ConvertFilePath(dir[i].name);
      dir[i].offset = SwapInt32(dir[i].offset);
      dir[i].size = SwapInt32(dir[i].size);
    }
  *dirsize_r = max;
  return dir;
}
예제 #2
0
 bool CmpParser::openFile(std::string filename){
     this->closeFile();
     file.open (filename.c_str(), std::fstream::in | std::fstream::binary);
     if (file.is_open()==false)
     return false;
     file.read((char*)&hdr,sizeof(HTKhdr));
     if (IsVAXOrder()){
         SwapShort(&hdr.sampSize);
         SwapShort(&hdr.sampKind);
         SwapInt32(&hdr.sampPeriod);
         SwapInt32(&hdr.nSamples);
     }
     return true;
     
 }
예제 #3
0
 bool CmpParser::readData(arma::Col<double> &data,short code){
     
     unsigned int dim=hdr.sampSize/4;
     data.resize(dim);
     if (code==0){
         float *p=new float;
         for (int i=0;i<dim;i++){
             if (file.read((char*)p,sizeof(float))==0)
             return false;
             SwapInt32((int*)p);
             data[i]=*p;
         }
         delete p;
     }
     return true;
 }
예제 #4
0
BViewState*
BViewState::InstantiateFromStream(BMallocIO* stream, bool endianSwap)
{
	// compare stream header in canonical form
	uint32 key = AttrHashString("BViewState", B_OBJECT_TYPE);
	int32 version = kViewStateArchiveVersion;

	if (endianSwap) {
		key = SwapUInt32(key);
		version = SwapInt32(version);
	}

	if (!ValidateStream(stream, key, version))
		return NULL;

	return _Sanitize(new (std::nothrow) BViewState(stream, endianSwap));
}
예제 #5
0
BColumn *
BColumn::InstantiateFromStream(BMallocIO *stream, bool endianSwap)
{
	// compare stream header in canonical form
	uint32 key = AttrHashString("BColumn", B_OBJECT_TYPE);
	int32 version = kColumnStateArchiveVersion;

	
	if (endianSwap) {
		key = SwapUInt32(key);
		version = SwapInt32(version);
	}

	// PRINT(("validating key %x, version %d\n", key, version));
	if (!ValidateStream(stream, key, version)) 
		return 0;

	// PRINT(("instantiating column, %s\n", endianSwap ? "endian swapping," : ""));
	BColumn *result = new BColumn(stream, endianSwap);
	
	// sanity-check the resulting column
	if (result->fTitle.Length() > 500
		|| result->fOffset < 0
		|| result->fOffset > 10000
		|| result->fWidth < 0
		|| result->fWidth > 10000
		|| (int32)result->fAlignment < B_ALIGN_LEFT
		|| (int32)result->fAlignment > B_ALIGN_CENTER
		|| result->fAttrName.Length() > 500) {
		PRINT(("column data not valid\n"));
		delete result;
		return 0;
	}
#if DEBUG
	else if (endianSwap)
		PRINT(("Instantiated foreign column ok\n"));
#endif

	return result;
}
예제 #6
0
BViewState *
BViewState::InstantiateFromStream(BMallocIO *stream, bool endianSwap)
{
	// compare stream header in canonical form
	uint32 key = AttrHashString("BViewState", B_OBJECT_TYPE);
	int32 version = kViewStateArchiveVersion;
	
	if (endianSwap) {
		key = SwapUInt32(key);
		version = SwapInt32(version);
	}

	if (!ValidateStream(stream, key, version)) 
		return NULL;

	BViewState *result = new BViewState(stream, endianSwap);
	
	// do a sanity check here
	if ((result->fViewMode != kListMode
			&& result->fViewMode != kIconMode
			&& result->fViewMode != kMiniIconMode
			&& result->fViewMode != 0)
		|| (result->fLastIconMode != kListMode
			&& result->fLastIconMode != kIconMode
			&& result->fLastIconMode != kMiniIconMode
			&& result->fLastIconMode != 0)) {
		
		PRINT(("Bad data instantiating ViewState, view mode %x, lastIconMode %x\n",
			result->fViewMode, result->fLastIconMode));

		delete result;
		return NULL;
	}
#if DEBUG
	else if (endianSwap)
		PRINT(("Instantiated foreign view state ok\n"));
#endif
	return result;
}
예제 #7
0
BColumn*
BColumn::InstantiateFromStream(BMallocIO* stream, bool endianSwap)
{
	// compare stream header in canonical form

	// we can't use ValidateStream(), as we preserve backwards compatibility
	int32 version;
	uint32 key;
	if (stream->Read(&key, sizeof(uint32)) <= 0
		|| stream->Read(&version, sizeof(int32)) <=0)
		return 0;

	if (endianSwap) {
		key = SwapUInt32(key);
		version = SwapInt32(version);
	}

	if (key != AttrHashString("BColumn", B_OBJECT_TYPE)
		|| version < kColumnStateMinArchiveVersion)
		return 0;

//	PRINT(("instantiating column, %s\n", endianSwap ? "endian swapping," : ""));
	return _Sanitize(new (std::nothrow) BColumn(stream, version, endianSwap));
}