int DecodeBibleVersion( struct RecordVersion* version, FILE* fp) { fread_blob(version->versionName, 16, fp); fread_blob(version->versionInfo, 128, fp); version->sepChar = fread_u8(fp); version->versionAttrib = fread_u8(fp); version->wordIndex = fread_u16(fp); version->totalWordRec = fread_u16(fp); version->totalBooks = fread_u16(fp); #ifdef PDB_DEBUG printf("version.versionName : %s\n", version->versionName); printf("version.versionInfo : "); printf_string(version->versionInfo, 128); printf("\n"); printf("version.sepChar : 0x%02x\n", version->sepChar); printf("version.versionAttrib : 0x%02x\n", version->versionAttrib); printf("version.wordIndex : 0x%04x\n", version->wordIndex); printf("version.totalWordRec: %d\n", version->totalWordRec); printf("version.totalBooks : %d\n", version->totalBooks); printf("\n"); #endif DecodeBibleBookBriefInfo(version->bookBriefInfo, version->totalBooks, fp); return 0; }
entry_found get_extended_entry( FILE * in_file, directory_entry * entry ) { int count; /* Get the defined_name_length. */ count = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) return( not_valid_entry ); /* Ensure the defined_name_length is not too long for the buffer. */ if( count > DEFINED_NAME_MAX ) { return( not_valid_entry ); } /* Get the defined_name. An empty value is allowed; see the Wiki. */ if( count > 0 ) { fread_buff( entry->defined_name, count, in_file ); if( ferror( in_file ) || feof( in_file ) ) { return( not_valid_entry ); } } entry->defined_name[count] = '\0'; /* Skip the marker. */ fseek( in_file, sizeof( uint16_t ), SEEK_CUR ); if( ferror( in_file ) || feof( in_file ) ) return( not_valid_entry ); /* Get the the member_name_length. */ count = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) return( not_valid_entry ); /* Ensure the member_name_length is not zero or too long for the buffer. */ if( (count == 0) || (count >= FILENAME_MAX) ) { return( not_valid_entry ); } /* Get the member_name. */ fread_buff( entry->member_name, count, in_file ); if( ferror( in_file ) || feof( in_file ) ) return( not_valid_entry ); entry->member_name[count] = '\0'; /* Skip the preview. */ fseek( in_file, sizeof( uint16_t ), SEEK_CUR ); if( ferror( in_file ) || feof( in_file ) ) return( valid_entry ); return( valid_entry ); }
int DecodeBibleWordTable( struct RecordWordTable* wordTable, FILE* fp) { int i = 0; wordTable->totalIndexes = fread_u16(fp); #ifdef PDB_DEBUG printf("wordTable.totalIndexes : %d\n", wordTable->totalIndexes); #endif for (i = 0;i < wordTable->totalIndexes;i++) { wordTable->wordBriefData[i].wordLength = fread_u16(fp); wordTable->wordBriefData[i].totalWord = fread_u16(fp); wordTable->wordBriefData[i].boolCompressed = fread_u8(fp); wordTable->wordBriefData[i].boolNothing = fread_u8(fp); } #ifdef PDB_DEBUG for (i = 0;i < wordTable->totalIndexes;i++) { printf("wordTable.wordBriefData[%d].wordLength : %d\n", i, wordTable->wordBriefData[i].wordLength); printf("wordTable.wordBriefData[%d].totalWord : %d\n", i, wordTable->wordBriefData[i].totalWord); printf("wordTable.wordBriefData[%d].boolCompressed : %d\n", i, wordTable->wordBriefData[i].boolCompressed); printf("wordTable.wordBriefData[%d].boolNothing : %d\n", i, wordTable->wordBriefData[i].boolNothing); printf("\n"); } #endif return 0; }
cop_font * parse_font( FILE * in_file, char const * in_name ) { /* The cop_font instance. */ cop_font * out_font = NULL; /* Used to acquire string attributes. */ uint8_t length; char * string_ptr = NULL; /* Used to acquire numeric attributes. */ uint16_t designator; /* Used to acquire the CharacterDescriptionBlock. */ uint8_t * byte_ptr = NULL; uint8_t data_count; uint16_t i; uint8_t intrans_flag; uint8_t * outtrans_data = NULL; uint8_t outtrans_data_size; uint8_t outtrans_flag; outtrans_block * outtrans_ptr = NULL; translation * translation_ptr = NULL; uint8_t * translation_start = NULL; uint8_t uint8_array[0x100]; uint16_t uint16_array[0x100]; uint8_t width_data_size; uint8_t width_flag; uint32_t * width_ptr; size_t size; /* Used for count and other values. */ uint8_t count8; /* Ensure in_name contains a value. */ if( in_name == NULL || (length = strlen( in_name )) == 0 ) return( out_font ); /* Initialize the out_font. */ out_font = mem_alloc( START_SIZE ); out_font->next_font = NULL; out_font->allocated_size = START_SIZE; out_font->next_offset = sizeof( cop_font ); /* Note: The various pointers must be entered, initially, as offsets * and then converted to pointers before returning because out_font * may be reallocated at any point and that invalidates actual pointers. */ /* Incorporate the defined name. */ length++; if( OUT_FONT_EXPAND_CHK( length ) ) { out_font = resize_cop_font( out_font, length ); } out_font->defined_name = OUT_FONT_CUR_OFF(); string_ptr = OUT_FONT_CUR_PTR(); strcpy( string_ptr, in_name ); OUT_FONT_ADD_OFF( length ); /* Get the font_out_name1. */ length = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } if( length > 0 ) { if( OUT_FONT_EXPAND_CHK( length + 1 ) ) { out_font = resize_cop_font( out_font, length + 1 ); } out_font->font_out_name1 = OUT_FONT_CUR_OFF(); string_ptr = OUT_FONT_CUR_PTR(); fread_buff( string_ptr, length, in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } string_ptr[length] = '\0'; OUT_FONT_ADD_OFF( length + 1 ); } else { out_font->font_out_name1 = NULL; } /* Get the font_out_name2. */ length = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } if( length > 0 ) { if( OUT_FONT_EXPAND_CHK( length + 1 ) ) { out_font = resize_cop_font( out_font, length + 1 ); } out_font->font_out_name2 = OUT_FONT_CUR_OFF(); string_ptr = OUT_FONT_CUR_PTR(); fread_buff( string_ptr, length, in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } string_ptr[length] = '\0'; OUT_FONT_ADD_OFF( length + 1 ); } else { out_font->font_out_name2 = NULL; } /* Get the designator and ensure it is 0x1D00. */ designator = fread_u16( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } if( designator != 0x1D00 ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the line_height. */ out_font->line_height = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the line_space. */ out_font->line_space = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the scale_basis. */ out_font->scale_basis = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the scale_min. */ out_font->scale_min = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the scale_max. */ out_font->scale_max = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the char_width. */ out_font->char_width = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the CharacterDescriptionBlock. */ /* Get the size_flag, which is not needed. */ count8 = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the data_count and the flags. */ width_flag = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } data_count = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } outtrans_flag = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } intrans_flag = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the IntransBlock, if present. */ if( intrans_flag == 0 ) { out_font->intrans = NULL; } else { /* Get the designator and verify it contains 0x81. */ count8 = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } if( count8 != 0x81 ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the count and verify that it contains 0x00. */ count8 = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } if( count8 != 0x00 ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the data into the array. */ if( OUT_FONT_EXPAND_CHK( sizeof( out_font->intrans->table ) ) ) { out_font = resize_cop_font( out_font, sizeof( out_font->intrans->table ) ); } out_font->intrans = OUT_FONT_CUR_OFF(); byte_ptr = OUT_FONT_CUR_PTR(); fread_buff( byte_ptr, 0x100, in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } OUT_FONT_ADD_OFF( sizeof( out_font->intrans->table ) ); } /* Get the OuttransBlock, if present. */ if( outtrans_flag == 0 ) { out_font->outtrans = NULL; } else { /* Get the next byte, which indicates the OuttransBlock data size. */ /* The name of the variable does not match the Wiki. */ outtrans_data_size = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Read the count. */ count8 = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* The file is positioned at the start of the data. */ /* Note: each translation is added individually; however, taken * together, they constitute the field "translations" in the Wiki. */ switch( outtrans_data_size) { case 0x81: /* The count should be 0x00. */ if( count8 != 0x00 ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the data into the local buffer. */ fread_buff( uint8_array, 0x100, in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Reserve space for the outtrans_block. */ if( OUT_FONT_EXPAND_CHK( sizeof( out_font->outtrans->table ) ) ) { out_font = resize_cop_font( out_font, sizeof( out_font->outtrans->table ) ); } out_font->outtrans = OUT_FONT_CUR_OFF(); outtrans_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( sizeof( out_font->outtrans->table ) ); /* Build the actual table, which requires actual pointers in * place of the offsets recorded in *out_font: * outtrans_ptr is the pointer version of out_font->outtrans. * for each iteration: * translation_ptr is the pointer version of * outtrans->ptr->table[i]. * byte_ptr is the pointer version of * translation_ptr->ptr.data. */ for( i = 0; i < 0x100; i++ ) { /* If the first byte matches the index, there is no translation. */ if( uint8_array[i] == i) { outtrans_ptr->table[i] = NULL; } else { /* Reserve space for the translation. */ if( OUT_FONT_EXPAND_CHK( sizeof( translation ) ) ) { out_font = resize_cop_font( out_font, sizeof( translation ) ); outtrans_ptr = OUT_FONT_MAP_OFF( out_font->outtrans ); } outtrans_ptr->table[i] = OUT_FONT_CUR_OFF(); /* Get the translation for the current character. */ translation_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( sizeof( translation ) ); /* The translation always contains exactly one character. */ size = 1; if( OUT_FONT_EXPAND_CHK( size ) ) { out_font = resize_cop_font( out_font, size ); outtrans_ptr = OUT_FONT_MAP_OFF( out_font->outtrans ); translation_ptr = OUT_FONT_MAP_OFF( outtrans_ptr->table[i] ); } translation_ptr->count = size; translation_ptr->data = OUT_FONT_CUR_OFF(); byte_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( size ); /* The translation character is the value in the input array. */ *byte_ptr = uint8_array[i]; } } break; case 0x82: /* The count should be equal to the data_count. */ if( count8 != data_count ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the outtrans array into the local array. */ for( i = 0; i < 0x100; i++ ) { uint16_array[i] = fread_u16( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } } /* Allocate a buffer and read the translation characters into it. */ outtrans_data = mem_alloc( data_count ); fread_buff( outtrans_data, data_count, in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( outtrans_data ); outtrans_data = NULL; mem_free( out_font ); out_font = NULL; return( out_font ); } /* Initialize outtrans_ptr and the outtrans pointer in out_font. */ if( OUT_FONT_EXPAND_CHK( sizeof( out_font->outtrans->table ) ) ) { out_font = resize_cop_font( out_font, sizeof( out_font->outtrans->table ) ); } out_font->outtrans = OUT_FONT_CUR_OFF(); outtrans_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( sizeof( out_font->outtrans->table ) ); translation_start = NULL; /* Convert the data in uint16_array to our format, which requires * actual pointers in place of the offsets recorded in *out_font: * outtrans_ptr is the pointer version of out_font->outtrans. * for each iteration: * translation_ptr is the pointer version of * outtrans->ptr->table[i]. * byte_ptr is the pointer version of * translation_ptr->ptr.data. */ for( i = 0; i < 0x100; i++ ) { /* If the first byte matches the index, there is no translation. */ if( uint16_array[i] == i) { outtrans_ptr->table[i] = NULL; } else { /* Reserve space for the translation. */ if( OUT_FONT_EXPAND_CHK( sizeof( translation ) ) ) { out_font = resize_cop_font( out_font, sizeof( translation ) ); outtrans_ptr = OUT_FONT_MAP_OFF( out_font->outtrans ); } outtrans_ptr->table[i] = OUT_FONT_CUR_OFF(); /* Get the translation for the current character. */ translation_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( sizeof( translation ) ); /* If the first byte at uint16_array[i] is 00, then the * second byte is the one-byte translation. Otherwise, the * second byte is an offset. For little-endian computers, * at least! */ /* Set the count correctly. */ if( (uint16_array[i] & 0xff00) == 0 ) { size = 1; } else { translation_start = outtrans_data + (uint16_array[i] & 0x00ff); size = *translation_start++; } /* Allocate space and perform other common operations. */ if( OUT_FONT_EXPAND_CHK( size ) ) { out_font = resize_cop_font( out_font, size ); outtrans_ptr = OUT_FONT_MAP_OFF( out_font->outtrans ); translation_ptr = OUT_FONT_MAP_OFF( outtrans_ptr->table[i] ); } translation_ptr->count = size; translation_ptr->data = OUT_FONT_CUR_OFF(); byte_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( size ); /* Put the data into the buffer. */ if( (uint16_array[i] & 0xff00) == 0x00 ) { *byte_ptr = (uint16_array[i] & 0x00ff); } else { memcpy( byte_ptr, translation_start, size ); } } } mem_free( outtrans_data ); outtrans_data = NULL; break; default: mem_free( out_font ); out_font = NULL; return( out_font ); } } /* Get the WidthBlock, if present. */ if( width_flag != 0 ) { out_font->width = NULL; } else { /* Reserve the space for width. */ if( OUT_FONT_EXPAND_CHK( sizeof( out_font->width->table ) ) ) { out_font = resize_cop_font( out_font, sizeof( out_font->width->table ) ); } out_font->width = OUT_FONT_CUR_OFF(); width_ptr = OUT_FONT_CUR_PTR(); OUT_FONT_ADD_OFF( sizeof( out_font->width->table ) ); /* Get the designator, which indicates the WidthBlock data size. */ /* The variable name does not match the field name in the Wiki. */ width_data_size = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* This byte's value is checked below. */ count8 = fread_u8( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* The file is now positioned at the start of the data. */ switch ( width_data_size ) { case 0x81: /* The WidthBlock has one-byte elements. */ /* The count should be 0x00. */ if( count8 != 0x00 ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the width data array into an array of bytes. * It cannot be read in directly because the field is * an array of uint32_t entries. */ fread_buff( uint8_array, 0x100, in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Copy the data into the cop_font instance. */ for( i = 0; i < 0x100; i++ ) { width_ptr[i] = uint8_array[i]; } break; case 0x84: /* The WidthBlock has four-byte elements. */ /* The count should be 0x01. */ if( count8 != 0x01 ) { mem_free( out_font ); out_font = NULL; return( out_font ); } /* Get the width data array directly into the cop_font instance. */ for( i = 0; i < 0x100; i++ ) { width_ptr[i] = fread_u32( in_file ); if( ferror( in_file ) || feof( in_file ) ) { mem_free( out_font ); out_font = NULL; return( out_font ); } } break; default: mem_free( out_font ); out_font = NULL; return( out_font ); } } /* Convert non-NULL offsets to pointers. */ if( out_font->defined_name != NULL ) { OUT_FONT_REMAP_MBR( defined_name ); } if( out_font->font_out_name1 != NULL ) { OUT_FONT_REMAP_MBR( font_out_name1 ); } if( out_font->font_out_name2 != NULL ) { OUT_FONT_REMAP_MBR( font_out_name2 ); } if( out_font->intrans != NULL ) { OUT_FONT_REMAP_MBR( intrans ); } if( out_font->outtrans != NULL ) { OUT_FONT_REMAP_MBR( outtrans ); for( i = 0; i < sizeof( outtrans_block ) / sizeof( translation * ); i++ ) { if( out_font->outtrans->table[i] != NULL ) { OUT_FONT_REMAP_MBR( outtrans->table[i] ); if( out_font->outtrans->table[i]->data != NULL ) { OUT_FONT_REMAP_MBR( outtrans->table[i]->data ); } } } } if( out_font->width != NULL ) { OUT_FONT_REMAP_MBR( width ); } return( out_font ); }
void ReadGameConfig(FILE *f) { use_offside = fread_u8(f); training = fread_u8(f); arcade = fread_u8(f); arcade_teams = fread_u8(f); free_longpass = fread_u8(f); injuries = fread_u8(f); bookings = fread_u8(f); substitutions = fread_u8(f); newchange = fread_u8(f); newpitches = fread_u8(f); detail_level = fread_u32(f); team_a = fread_u8(f); team_b = fread_u8(f); field = fread_u8(f); strictness = fread_u8(f); fread_data(&player_type, sizeof(player_type), f); current_field = fread_u8(f); fread_data(&shirt, sizeof(shirt), f); fread_data(&palette, sizeof(palette), f); fread_data(&fieldname, sizeof(fieldname), f); time_length = fread_u32(f); }