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; }
/////////////////////////////////////////////////////////////////////////////// //Local PDB decode interface define int DecodePDBHeader(struct PDBHeader* header, FILE* fp) { //Fill pdb header fread_blob(header->fileName, 32, fp); header->fileAttributes = fread_u16(fp); header->versionNumber = fread_u16(fp); header->createDate = fread_u32(fp); header->modificationDate = fread_u32(fp); header->lastBackupDate = fread_u32(fp); header->modificationNumber = fread_u32(fp); header->appInfoArea = fread_u32(fp); header->sortInfoArea = fread_u32(fp); fread_blob(header->dataBaseType, 4, fp); fread_blob(header->creatorID, 4, fp); fread_blob(header->uniqueIDSeed, 4, fp); header->nextRecord = fread_u32(fp); header->numRecs = fread_u16(fp); #ifdef PDB_DEBUG //Debug info printf("header->FileName : %s\n", header->fileName); printf("header->DatabaseType: "); printf_string(header->dataBaseType, 4); printf("\n"); printf("header->CreatorID : "); printf_string(header->creatorID, 4); printf("\n"); printf("header->NumRecs : 0x%02x\n",header->numRecs); #endif return 0; }
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; }
int DecodeBibleBookBriefInfo( struct BookBriefInfo* bookBriefInfo, int nrOfBooks, FILE* fp) { int i = 0; for (i = 0;i < nrOfBooks;i++) { bookBriefInfo[i].bookNum = fread_u16(fp); bookBriefInfo[i].bookIndex = fread_u16(fp); bookBriefInfo[i].totalBookRec = fread_u16(fp); fread_blob(bookBriefInfo[i].simpleName, 8, fp); fread_blob(bookBriefInfo[i].complexName, 32, fp); } #ifdef PDB_DEBUG for (i = 0;i < nrOfBooks;i++) { printf("version.bookBriefInfo[%d].bookNum : %d\n", i, bookBriefInfo[i].bookNum); printf("version.bookBriefInfo[%d].bookIndex : %d\n", i, bookBriefInfo[i].bookIndex); printf("version.bookBriefInfo[%d].totalBookRec : %d\n", i, bookBriefInfo[i].totalBookRec); printf("version.bookBriefInfo[%d].simpleName : %s\n", i, bookBriefInfo[i].simpleName); printf("version.bookBriefInfo[%d].complexName : %s\n", i, bookBriefInfo[i].complexName); printf("\n"); } #endif return 0; }
char * get_member_name( char const * in_name ) { char * member_name = NULL; cop_file_type file_type; directory_entry current_entry; entry_found entry_status; size_t member_length; uint16_t entry_type; /* See if in_name is found in try_file_name. */ file_type = parse_header( try_fp ); switch( file_type ) { case file_error: /* File error, including premature eof. */ xx_simple_err_c( err_dev_lib_file, try_file_name ); break; case not_se_v4_1: /* File was created by a different version of gendev. */ xx_simple_err( err_wrong_gendev ); break; case not_bin_dev: case se_v4_1_not_dir: /* Wrong type of file: something is wrong with the device library. */ xx_simple_err_c( err_dev_lib_data, try_file_name ); break; case dir_v4_1_se: /* try_fp was a same-endian version 4.1 directory file. */ /* Skip the number of entries. */ fseek( try_fp, sizeof( uint32_t ), SEEK_CUR ); if( ferror( try_fp ) || feof( try_fp ) ) { break; } for( ;; ) { /* Get the entry_type. This is either the type or the metatype, * depending on whether this is a CompactDirEntry or an * ExtendedDirEntry. */ entry_type = fread_u16( try_fp ); /* Exit the loop when the final entry has been processed. */ if( feof( try_fp ) || ferror( try_fp ) ) { break; } switch( entry_type) { case 0x0000: /* This should only happen when the end-of-file padding is * reached, but continue in case there is more data. */ continue; case 0x0001: /* This will be an ExtendedDirEntry. */ for( ;; ) { /* Get the entry_type. This is always the type, since the * metatype has already been read. */ entry_type = fread_u16( try_fp ); /* Exit the loop when the final entry has been processed. */ if( feof( try_fp ) || ferror( try_fp ) ) { break; } switch( entry_type ) { case 0x0000: /* This should only happen when the end-of-file padding is * reached, but continue in case there is more data. */ continue; case 0x0001: /* This should never actually occur; however, continue * in case there is more data. */ continue; case 0x0101: case 0x0201: case 0x0401: /* For any type, check the defined name. */ entry_status = get_extended_entry( try_fp, ¤t_entry ); switch( entry_status ) { case valid_entry: /* Return the member name, if found. */ if( !stricmp( in_name, current_entry.defined_name ) ) { member_length = strlen( current_entry.member_name ) + 1; member_name = mem_alloc( member_length ); strcpy( member_name, current_entry.member_name ); return( member_name ); } break; case not_valid_entry: break; default: /* The entry_status is an unknown value. */ internal_err( __FILE__, __LINE__ ); break; } break; default: /* The entry_type is an unknown value. */ internal_err( __FILE__, __LINE__ ); break; } break; } break; case 0x0101: case 0x0201: case 0x0401: /* For any type, check the defined name. */ entry_status = get_compact_entry( try_fp, ¤t_entry ); switch( entry_status ) { case valid_entry: /* Return the member name, if found. */ if( !stricmp( in_name, current_entry.defined_name) ) { member_length = strlen( current_entry.member_name ) + 1; member_name = mem_alloc( member_length ); strcpy( member_name, current_entry.member_name ); return( member_name ); } break; case not_valid_entry: break; default: /* The entry_status is an unknown value. */ internal_err( __FILE__, __LINE__ ); break; } break; default: /* The entry_type is an unknown value. */ internal_err( __FILE__, __LINE__ ); break; } } break; default: /* The file_type is an unknown value. */ internal_err( __FILE__, __LINE__ ); break; } return( member_name ); }
int DecodeBibleBookDetailInfo( struct BookDetailInfo* bookDetailInfo, FILE* fp) { int i = 0; uint16_t numChapters = 0; uint32_t lastVerseNumber = 0; //Read number of chapters bookDetailInfo->numChapters = fread_u16(fp); #ifdef PDB_DEBUG printf("bookDetailInfo.numChapters : %d\n", bookDetailInfo->numChapters); #endif //Read last verse number table numChapters = bookDetailInfo->numChapters; bookDetailInfo->lastVerseNumber = (uint16_t*)malloc(sizeof(uint16_t) * numChapters); if (bookDetailInfo->lastVerseNumber == NULL) { MSG_MALLOC_FAIL(bookDetailInfo->lastVerseNumber); return -1; } else { for (i = 0;i < numChapters;i++) { bookDetailInfo->lastVerseNumber[i] = fread_u16(fp); } #ifdef PDB_DEBUG printf("bookDetailInfo.lastVerseNumber : ...\n"); #endif } //Read chapter offset table bookDetailInfo->chapterOffset = (uint32_t*)malloc(sizeof(uint32_t) * numChapters); if (bookDetailInfo->chapterOffset == NULL) { free(bookDetailInfo->lastVerseNumber); bookDetailInfo->lastVerseNumber = NULL; MSG_MALLOC_FAIL(bookDetailInfo->chapterOffset); return -1; } else { for (i = 0;i < numChapters;i++) { bookDetailInfo->chapterOffset[i] = fread_u32(fp); } #ifdef PDB_DEBUG printf("bookDetailInfo.chapterOffset : ...\n"); #endif } //Read verse offset table lastVerseNumber = bookDetailInfo->lastVerseNumber[numChapters - 1]; bookDetailInfo->verseOffset = (uint16_t*)malloc(sizeof(uint16_t) * lastVerseNumber); if (bookDetailInfo->verseOffset == NULL) { free(bookDetailInfo->lastVerseNumber); bookDetailInfo->lastVerseNumber = NULL; free(bookDetailInfo->chapterOffset); bookDetailInfo->chapterOffset = NULL; MSG_MALLOC_FAIL(bookDetailInfo->verseOffset); return -1; } else { for (i = 0;i < lastVerseNumber;i++) { bookDetailInfo->verseOffset[i] = fread_u16(fp); } #ifdef PDB_DEBUG printf("bookDetailInfo.verseOffset : ...\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 ); }