void lha_reader_free(LHAReader *reader) { LHAFileHeader *header; if (reader->decoder != NULL) { if (reader->inner_decoder == reader->decoder) { reader->inner_decoder = NULL; } lha_decoder_free(reader->decoder); } if (reader->inner_decoder != NULL) { lha_decoder_free(reader->inner_decoder); } // Free any file headers in the stack. while (reader->dir_stack != NULL) { header = reader->dir_stack; reader->dir_stack = header->_next; lha_file_header_free(header); } lha_basic_reader_free(reader->reader); free(reader); }
LHAFileHeader *lha_reader_next_file(LHAReader *reader) { // Free the current decoder if there is one. if (reader->decoder != NULL) { if (reader->inner_decoder == reader->decoder) { reader->inner_decoder = NULL; } lha_decoder_free(reader->decoder); reader->decoder = NULL; } if (reader->inner_decoder != NULL) { lha_decoder_free(reader->inner_decoder); reader->inner_decoder = NULL; } // No point continuing once the end of the input stream has // been reached. if (reader->curr_file_type == CURR_FILE_EOF) { return NULL; } // Advance to the next file from the input stream? // Don't advance until we've done the fake directories first. if (reader->curr_file_type == CURR_FILE_START || reader->curr_file_type == CURR_FILE_NORMAL) { lha_basic_reader_next_file(reader->reader); } // Pop off all appropriate directories from the stack first. if (end_of_top_dir(reader)) { reader->curr_file = reader->dir_stack; reader->dir_stack = reader->dir_stack->_next; reader->curr_file_type = CURR_FILE_FAKE_DIR; } else { reader->curr_file = lha_basic_reader_curr_file(reader->reader); if (reader->curr_file != NULL) { reader->curr_file_type = CURR_FILE_NORMAL; } else { reader->curr_file_type = CURR_FILE_EOF; } } return reader->curr_file; }
int loadTD0(Computer* comp, const char* name, int drv) { Floppy* flp = comp->dif->fdc->flop[drv & 3]; FILE* file = fopen(name, "rb"); if (!file) return ERR_CANT_OPEN; int err = ERR_OK; td0Head hd; fread(&hd, sizeof(td0Head), 1, file); if (strncmp(hd.sign, "td", 2) && strncmp(hd.sign, "TD", 2)) { err = ERR_TD0_SIGN; } else if ((hd.dens != 0) || (hd.sides > 2)) { err = ERR_TD0_TYPE; } else if (hd.ver < 0x14) { err = ERR_TD0_VERSION; } else { if (strncmp(hd.sign,"TD",2)) { // 1 on td (packed) LHADecoderType* decType; LHADecoder* dec = NULL; decType = lha_decoder_for_name("-lh1-"); dec = lha_decoder_new(decType, fGetData, file, -1); doTD0(flp, lhaDepack, dec, hd.flag & 0x80); lha_decoder_free(dec); } else { doTD0(flp, fGetData, file, hd.flag & 0x80); } flp->path = (char*)realloc(flp->path,sizeof(char) * (strlen(name) + 1)); strcpy(flp->path,name); flp->insert = 1; flp->changed = 0; } fclose(file); return err; }