/* Displays contents of ".COD" files
Copyright 2001-2005 Scott Dattalo
Copyright 2012 Borut Ražem
Copyright 2016 Molnár Károly
*/
#include "stdhdr.h"
#include "libgputils.h"
#include "gpvc.h"
#include "dump.h"
#include "block.h"
/*------------------------------------------------------------------------------------------------*/
void
read_block(FILE *Code_file, uint8_t *Cblock, unsigned Block_number)
{
size_t n;
fseek(Code_file, Block_number * COD_BLOCK_SIZE, SEEK_SET);
n = fread(Cblock, 1, COD_BLOCK_SIZE, Code_file);
if (n != COD_BLOCK_SIZE) {
gp_error("Bad block number: %u", Block_number);
}
}
/*------------------------------------------------------------------------------------------------*/
DirBlockInfo* read_directory(FILE *Code_file) {
DirBlockInfo *head;
DirBlockInfo *tail;
unsigned next_dir_block;
next_dir_block = 0;
head = NULL;
tail = NULL;
do {
DirBlockInfo *dbi = new DirBlockInfo;
if (!head) head = dbi;
else tail->next = dbi;
tail = dbi;
read_block(Code_file, dbi->dir, next_dir_block);
next_dir_block = gp_getl16(&dbi->dir[COD_DIR_NEXTDIR]);
} while (next_dir_block != 0);
tail->next = NULL;
return head;
}
Detected encoding: UTF-8 | 0
|