예제 #1
0
파일: oresdb.cpp 프로젝트: mecirt/7k2
//---------- Begin of function ResourceDb::read ----------//
//
// Read in data from the resource file and store in an the buffer of this class
//
// The index field of the current record in the database object is
// used to locate the data in the resource file.
//
// Syntax : read(int recNo)
//
// [int] recNo = the record no. in the database.
//               (default : current record no.)
//
// Return : <char*> data pointer
//          NULL    if the record has not index to data
//
char* ResourceDb::read(int recNo)
{
   err_when( !init_flag || !db_obj );

   long* indexFieldPtr;
	char* recPtr;

   if( (recPtr = db_obj->read(recNo)) == NULL )
      return NULL;

   indexFieldPtr = (long*) (recPtr+index_field_offset);

   if( memcmp( indexFieldPtr, "    ", 4 ) == 0 )
      return NULL;      // no sample screen for this file

   file_seek( *indexFieldPtr );
	data_buf_size = file_get_long();

	err_when( use_common_buf && data_buf_size > COMMON_DATA_BUF_SIZE );

   if( !use_common_buf )
		data_buf = mem_resize( data_buf, data_buf_size );

	file_read( data_buf, data_buf_size );

   return data_buf;
}
예제 #2
0
파일: ORESDB.cpp 프로젝트: AMDmi3/7kaa
//---------- Begin of function ResourceDb::read_imported ----------//
//
// If ResourceDb is initialized using init_imported(),
// then use read_imported to read the record
//
// <long> offset = offset to the data in the resource file
//
// Return : <char*> data pointer
//          NULL    if the record has not index to data
//
char* ResourceDb::read_imported(long offset)
{
	err_when(!init_flag);

	//-------- read from buffer ---------//
	// ##### begin Gilbert 4/10 #######//
	if( read_all )
	{
		err_when(offset < 0 || offset >= data_buf_size);
		return data_buf + offset + sizeof(int32_t);  // bypass the long parameters which is the size of the data
	}
	// ##### end Gilbert 4/10 #######//

	//---------- read from file ---------//

	// ##### begin Gilbert 2/10 ######//
	err_when(offset >= file_size());
	// ##### end Gilbert 2/10 ######//
	file_seek( offset );

	data_buf_size = file_get_long();

	err_when(use_common_buf && data_buf_size > COMMON_DATA_BUF_SIZE);

   if( !use_common_buf )
		data_buf = mem_resize( data_buf, data_buf_size );

	file_read( data_buf, data_buf_size );

   return data_buf;
}