/* stack dump and information dump * for stack dump, a common rules is: * 0x2000xxxx (r7) 0x0000xxxx(lr), r7 will in stack and lr will in flash. * usually 12th long word is the address which calls panic(). */ void panic(char *infostr) { uint32_t sp; uint32_t size; fsave(); kprintf("PANIC: %s\n", infostr); #if 0 if(get_psr() & 0xFF){ /* in exception context, dump exception stack */ sp = __get_MSP(); if((sp>(uint32_t)_irq_stack_start) && (sp<(uint32_t)_irq_stack_start+1024)) { size = (uint32_t)_irq_stack_start+1024-sp; kprintf("exception stacks: sp=0x%x depth=%d bytes\n", sp, size); dump_buffer((uint8_t *)sp, size); } else kprintf("broken MSP: 0x%x\n", sp); } if((current>=&systask[0]) && (current<&systask[MAX_TASK_NUMBER])) { /* dump task stack */ sp = __get_PSP(); if((sp>(uint32_t)current->stack_base) && (sp<(uint32_t)current->stack_base+current->stack_size)) { size = (uint32_t)current->stack_base+current->stack_size-sp; kprintf("task stacks: sp=0x%x depth=%d bytes\n", sp, size); dump_buffer((uint8_t *)sp, size); } else kprintf("broken PSP: 0x%x\n", sp); /* dump current task info */ kprintf("current=0x%x last sp=0x%x stack_base=0x%x taskname=%s state=%d taskq=0x%x\n", current, current->sp, current->stack_base, current->name, current->state, current->taskq); } else kprintf("current is overwriten! current=0x%x\n", current); #endif // 0 /* dump system ready queue */ /* dump memory usage */ memory_dump(); while(1); }
void Collection_Onglet::saveContexte() { std::ofstream fsave("save.dat"); if(!fsave) { throw CalculException("Ouverture fichier impossible, sauvegarde non assuree"); } Onglet *o=0; fsave << "<root>"; for(int i=0; i<Collection_Onglet::GetInstance().size(); ++i) { o = Collection_Onglet::GetInstance().at(i); fsave << "<onglet>"; fsave << o->sauverContexte(); fsave << "</onglet>"; } fsave << "</root>"; fsave.close(); }
//Saves the tree into the binary file. //Nodes packed into the file in preorder. void CTree::save(const char* fileName) { fstream fsave(fileName, ios_base::binary | ios_base::out | ios_base::app); //file stack<CTreeNode*> nodes; //stack for keeping roots of subtrees in the packing order nodes.push(&root); while(!nodes.empty()) { CTreeNode* pNode = nodes.top(); //current node to be packed nodes.pop(); pNode->save(fsave); if(!pNode->isLeaf()) { nodes.push(pNode->right); nodes.push(pNode->left); } } fsave.close(); }
//ag_merge [-n _start_N_value_] [-a _start_alpha_value_] -d _directory1_ _directory2_ [_directory3_] //[_directory4_] ... int main(int argc, char* argv[]) { try{ //0. Set log file LogStream clog; LogStream::init(true); clog << "\n-----\nag_merge "; for(int argNo = 1; argNo < argc; argNo++) clog << argv[argNo] << " "; clog << "\n\n"; //1. Set input parameters from command line int startTiGN = 1; double startAlpha = 0.5; int firstDirNo = 0; stringv args(argc); for(int argNo = 0; argNo < argc; argNo++) args[argNo] = string(argv[argNo]); //parse and save input parameters for(int argNo = 1; argNo < argc; argNo += 2) { if(!args[argNo].compare("-n")) startTiGN = atoiExt(argv[argNo + 1]); else if(!args[argNo].compare("-a")) startAlpha = atofExt(argv[argNo + 1]); else if(!args[argNo].compare("-d")) { firstDirNo = argNo + 1; break; } else throw INPUT_ERR; } //check that there are at least two directories if(argc < (firstDirNo + 2)) throw INPUT_ERR; //convert names of input directories to strings and check that they exist int folderN = argc - firstDirNo; stringv folders(folderN); for(int argNo = firstDirNo; argNo < argc; argNo++) { folders[argNo - firstDirNo] = string(argv[argNo]); struct stat status; if((stat(argv[argNo], &status) != 0) || !(status.st_mode & S_IFDIR)) throw DIR_ERR; } //1.a) delete all temp files from the previous run and create a directory AGTemp #ifdef _WIN32 //in windows CreateDirectory("AGTemp", NULL); #else // in linux system("rm -rf ./AGTemp/"); system("mkdir ./AGTemp/"); #endif //2. Set parameters from AGTemp/params.txt from the first directory TrainInfo ti; //set of model parameters in the current directory double prevBest; //best value of performance achieved on the previous run fstream fparam; string paramPathName = folders[0] + "/AGTemp/params.txt"; fparam.open(paramPathName.c_str(), ios_base::in); string modeStr, metric; fparam >> ti.seed >> ti.trainFName >> ti.validFName >> ti.attrFName >> ti.minAlpha >> ti.maxTiGN >> ti.bagN >> modeStr >> metric; //modeStr should be "fast" or "slow" or "layered" if(modeStr.compare("fast") == 0) ti.mode = FAST; else if(modeStr.compare("slow") == 0) ti.mode = SLOW; else if(modeStr.compare("layered") == 0) ti.mode = LAYERED; else throw TEMP_ERR; //metric should be "roc" or "rms" if(metric.compare("rms") == 0) ti.rms = true; else if(metric.compare("roc") == 0) ti.rms = false; else throw TEMP_ERR; if(fparam.fail()) throw TEMP_ERR; fparam.close(); fparam.clear(); //read best value of performance on previous run fstream fbest; double stub; int itemN; // number of data points in the train set, need to calculate possible values of alpha string fbestPathName = folders[0] + "/AGTemp/best.txt"; fbest.open(fbestPathName.c_str(), ios_base::in); fbest >> prevBest >> stub >> stub >> stub >> itemN; if(fbest.fail()) throw TEMP_ERR; fbest.close(); int alphaN = getAlphaN(ti.minAlpha, itemN); //number of different alpha values int tigNN = getTiGNN(ti.maxTiGN); //direction of initialization (1 - up, 0 - right), used in fast mode only doublevv dir(tigNN, doublev(alphaN, 0)); //outer array: column (by TiGN) //middle array: row (by alpha) //direction of initialization (1 - up, 0 - right), collects average in the slow mode doublevv dirStat(tigNN, doublev(alphaN, 0)); if(ti.mode == FAST) {//read part of the directions table from file fstream fdir; string fdirPathName = folders[0] + "/AGTemp/dir.txt"; fdir.open(fdirPathName.c_str(), ios_base::in); for(int tigNNo = 0; tigNNo < tigNN; tigNNo++) for(int alphaNo = 0; alphaNo < alphaN; alphaNo++) fdir >> dir[tigNNo][alphaNo]; if(fdir.fail()) throw TEMP_ERR; fdir.close(); } //3. Read main parameters from all other directories and check that they match int allBagN = ti.bagN; intv bagNs(folderN, 0); bagNs[0] = ti.bagN; intv prevBagNs(folderN + 1, 0); //sums of bagNs of all previous directories prevBagNs[1] = ti.bagN; int lastSeed = ti.seed; for(int folderNo = 1; folderNo < folderN; folderNo++) { TrainInfo extraTI; //set of model parameters in the additional directory string fparamPathName = folders[folderNo] + "/AGTemp/params.txt"; fparam.open(fparamPathName.c_str(), ios_base::in); fparam >> extraTI.seed >> extraTI.trainFName >> extraTI.validFName >> extraTI.attrFName >> extraTI.minAlpha >> extraTI.maxTiGN >> extraTI.bagN; if(fparam.fail()) { clog << fparamPathName << '\n'; throw TEMP_ERR; } fparam.close(); if((ti.minAlpha != extraTI.minAlpha) || (ti.maxTiGN != extraTI.maxTiGN)) { clog << fparamPathName << '\n'; throw MERGE_MISMATCH_ERR; } if(extraTI.seed == ti.seed) throw SAME_SEED_ERR; if(folderNo == (folderN - 1)) lastSeed = extraTI.seed; allBagN += extraTI.bagN; bagNs[folderNo] = extraTI.bagN; prevBagNs[folderNo + 1] = allBagN; string fdirStatPathName = folders[folderNo] + "/AGTemp/dirstat.txt"; fstream fdirStat; fdirStat.open("./AGTemp/dirstat.txt", ios_base::in); for(int alphaNo = 0; alphaNo < alphaN; alphaNo++) for(int tigNNo = 0; tigNNo < tigNN; tigNNo++) { double ds; fdirStat >> ds; dirStat[tigNNo][alphaNo] += ds * extraTI.bagN; } } //4. Load data INDdata data("", ti.validFName.c_str(), "", ti.attrFName.c_str()); CGrove::setData(data); CTreeNode::setData(data); doublev validTar; int validN = data.getTargets(validTar, VALID); clog << "Alpha = " << ti.minAlpha << "\nN = " << ti.maxTiGN << "\n" << allBagN << " bagging iterations\n"; if(ti.mode == FAST) clog << "fast mode\n\n"; else if(ti.mode == SLOW) clog << "slow mode\n\n"; else //if(ti.mode == LAYERED) clog << "layered mode\n\n"; //5. Initialize some internal process variables //surfaces of performance values for validation set. //Always calculate rms (for convergence analysis), if needed, calculate roc doublevvv rmsV(tigNN, doublevv(alphaN, doublev(allBagN, 0))); doublevvv rocV; if(!ti.rms) rocV.resize(tigNN, doublevv(alphaN, doublev(allBagN, 0))); //outer array: column (by TiGN) //middle array: row (by alpha) //inner array: bagging iterations. Performance is kept for all iterations to create bagging curves //sums of predictions for each data point (raw material to calculate performance) doublevvv predsumsV(tigNN, doublevv(alphaN, doublev(validN, 0))); //outer array: column (by TiGN) //middle array: row (by alpha) //inner array: data points in the validation set //6. Read and merge models from the directories int startAlphaNo = getAlphaN(startAlpha, itemN) - 1; int startTiGNNo = getTiGNN(startTiGN) - 1; for(int alphaNo = startAlphaNo; alphaNo < alphaN; alphaNo++) { double alpha; if(alphaNo < alphaN - 1) alpha = alphaVal(alphaNo); else //this is a special case because minAlpha can be zero alpha = ti.minAlpha; cout << "Merging models with alpha = " << alpha << endl; for(int tigNNo = startTiGNNo; tigNNo < tigNN; tigNNo++) { int tigN = tigVal(tigNNo); //number of trees in the current grove //temp file in the extra directory that keeps models corresponding to alpha and tigN string prefix = string("/AGTemp/ag.a.") + alphaToStr(alpha) + ".n." + itoa(tigN, 10); string tempFName = prefix + ".tmp"; //this will kill the pre-existing file in the output directory fstream fsave((string(".") + tempFName).c_str(), ios_base::binary | ios_base::out); for(int folderNo = 0; folderNo < folderN; folderNo++) { string inTempFName = folders[folderNo] + tempFName; fstream ftemp((inTempFName).c_str(), ios_base::binary | ios_base::in); if(ftemp.fail()) { clog << inTempFName << '\n'; throw TEMP_ERR; } //merge all extra models with the same (alpha, tigN) parameter values into existing models for(int bagNo = prevBagNs[folderNo]; bagNo < prevBagNs[folderNo + 1]; bagNo++) { //retrieve next grove CGrove extraGrove(alpha, tigN); try{ extraGrove.load(ftemp); }catch(TE_ERROR err){ clog << inTempFName << '\n'; throw err; } //add the loaded grove to a model file with alpha and tigN values in the name extraGrove.save((string(".") + tempFName).c_str()); //generate predictions and performance for validation set doublev predictions(validN); for(int itemNo = 0; itemNo < validN; itemNo++) { predsumsV[tigNNo][alphaNo][itemNo] += extraGrove.predict(itemNo, VALID); predictions[itemNo] = predsumsV[tigNNo][alphaNo][itemNo] / (bagNo + 1); } if(bagNo == allBagN - 1) { string predsFName = prefix + ".preds.txt"; fstream fpreds((string(".") + predsFName).c_str(), ios_base::out); for(int itemNo = 0; itemNo < validN; itemNo++) fpreds << predictions[itemNo] << endl; fpreds.close(); } rmsV[tigNNo][alphaNo][bagNo] = rmse(predictions, validTar); if(!ti.rms) rocV[tigNNo][alphaNo][bagNo] = roc(predictions, validTar); }// end for(int bagNo = ti.bagN; bagNo < ti.bagN + extraTI.bagN; bagNo++) ftemp.close(); }//end for(int folderNo = 0; folderNo < folderN; folderNo++) }//end for(int tigNNo = 0; tigNNo < tigNN; tigNNo++) }//end for(int alphaNo = 0; alphaNo < alphaN; alphaNo++) //4. Output ti.bagN = allBagN; ti.seed = lastSeed; if(ti.rms) trainOut(ti, dir, rmsV, rmsV, predsumsV, itemN, dirStat, startAlphaNo, startTiGNNo); else trainOut(ti, dir, rmsV, rocV, predsumsV, itemN, dirStat, startAlphaNo, startTiGNNo); }catch(TE_ERROR err){
int FPU_load_store(u_char type, fpu_addr_modes addr_modes, void __user *data_address) { FPU_REG loaded_data; FPU_REG *st0_ptr; u_char st0_tag = TAG_Empty; /* This is just to stop a gcc warning. */ u_char loaded_tag; st0_ptr = NULL; /* Initialized just to stop compiler warnings. */ if ( addr_modes.default_mode & PROTECTED ) { if ( addr_modes.default_mode == SEG32 ) { if ( access_limit < data_sizes_32[type] ) math_abort(FPU_info,SIGSEGV); } else if ( addr_modes.default_mode == PM16 ) { if ( access_limit < data_sizes_16[type] ) math_abort(FPU_info,SIGSEGV); } #ifdef PARANOID else EXCEPTION(EX_INTERNAL|0x140); #endif /* PARANOID */ } switch ( type_table[type] ) { case _NONE_: break; case _REG0_: st0_ptr = &st(0); /* Some of these instructions pop after storing */ st0_tag = FPU_gettag0(); break; case _PUSH_: { if ( FPU_gettagi(-1) != TAG_Empty ) { FPU_stack_overflow(); return 0; } top--; st0_ptr = &st(0); } break; case _null_: FPU_illegal(); return 0; #ifdef PARANOID default: EXCEPTION(EX_INTERNAL|0x141); return 0; #endif /* PARANOID */ } switch ( type ) { case 000: /* fld m32real */ clear_C1(); loaded_tag = FPU_load_single((float __user *)data_address, &loaded_data); if ( (loaded_tag == TAG_Special) && isNaN(&loaded_data) && (real_1op_NaN(&loaded_data) < 0) ) { top++; break; } FPU_copy_to_reg0(&loaded_data, loaded_tag); break; case 001: /* fild m32int */ clear_C1(); loaded_tag = FPU_load_int32((long __user *)data_address, &loaded_data); FPU_copy_to_reg0(&loaded_data, loaded_tag); break; case 002: /* fld m64real */ clear_C1(); loaded_tag = FPU_load_double((double __user *)data_address, &loaded_data); if ( (loaded_tag == TAG_Special) && isNaN(&loaded_data) && (real_1op_NaN(&loaded_data) < 0) ) { top++; break; } FPU_copy_to_reg0(&loaded_data, loaded_tag); break; case 003: /* fild m16int */ clear_C1(); loaded_tag = FPU_load_int16((short __user *)data_address, &loaded_data); FPU_copy_to_reg0(&loaded_data, loaded_tag); break; case 010: /* fst m32real */ clear_C1(); FPU_store_single(st0_ptr, st0_tag, (float __user *)data_address); break; case 011: /* fist m32int */ clear_C1(); FPU_store_int32(st0_ptr, st0_tag, (long __user *)data_address); break; case 012: /* fst m64real */ clear_C1(); FPU_store_double(st0_ptr, st0_tag, (double __user *)data_address); break; case 013: /* fist m16int */ clear_C1(); FPU_store_int16(st0_ptr, st0_tag, (short __user *)data_address); break; case 014: /* fstp m32real */ clear_C1(); if ( FPU_store_single(st0_ptr, st0_tag, (float __user *)data_address) ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; case 015: /* fistp m32int */ clear_C1(); if ( FPU_store_int32(st0_ptr, st0_tag, (long __user *)data_address) ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; case 016: /* fstp m64real */ clear_C1(); if ( FPU_store_double(st0_ptr, st0_tag, (double __user *)data_address) ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; case 017: /* fistp m16int */ clear_C1(); if ( FPU_store_int16(st0_ptr, st0_tag, (short __user *)data_address) ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; case 020: /* fldenv m14/28byte */ fldenv(addr_modes, (u_char __user *)data_address); /* Ensure that the values just loaded are not changed by fix-up operations. */ return 1; case 022: /* frstor m94/108byte */ frstor(addr_modes, (u_char __user *)data_address); /* Ensure that the values just loaded are not changed by fix-up operations. */ return 1; case 023: /* fbld m80dec */ clear_C1(); loaded_tag = FPU_load_bcd((u_char __user *)data_address); FPU_settag0(loaded_tag); break; case 024: /* fldcw */ RE_ENTRANT_CHECK_OFF; FPU_verify_area(VERIFY_READ, data_address, 2); FPU_get_user(control_word, (unsigned short __user *) data_address); RE_ENTRANT_CHECK_ON; if ( partial_status & ~control_word & CW_Exceptions ) partial_status |= (SW_Summary | SW_Backward); else partial_status &= ~(SW_Summary | SW_Backward); #ifdef PECULIAR_486 control_word |= 0x40; /* An 80486 appears to always set this bit */ #endif /* PECULIAR_486 */ return 1; case 025: /* fld m80real */ clear_C1(); loaded_tag = FPU_load_extended((long double __user *)data_address, 0); FPU_settag0(loaded_tag); break; case 027: /* fild m64int */ clear_C1(); loaded_tag = FPU_load_int64((long long __user *)data_address); FPU_settag0(loaded_tag); break; case 030: /* fstenv m14/28byte */ fstenv(addr_modes, (u_char __user *)data_address); return 1; case 032: /* fsave */ fsave(addr_modes, (u_char __user *)data_address); return 1; case 033: /* fbstp m80dec */ clear_C1(); if ( FPU_store_bcd(st0_ptr, st0_tag, (u_char __user *)data_address) ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; case 034: /* fstcw m16int */ RE_ENTRANT_CHECK_OFF; FPU_verify_area(VERIFY_WRITE,data_address,2); FPU_put_user(control_word, (unsigned short __user *) data_address); RE_ENTRANT_CHECK_ON; return 1; case 035: /* fstp m80real */ clear_C1(); if ( FPU_store_extended(st0_ptr, st0_tag, (long double __user *)data_address) ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; case 036: /* fstsw m2byte */ RE_ENTRANT_CHECK_OFF; FPU_verify_area(VERIFY_WRITE,data_address,2); FPU_put_user(status_word(),(unsigned short __user *) data_address); RE_ENTRANT_CHECK_ON; return 1; case 037: /* fistp m64int */ clear_C1(); if ( FPU_store_int64(st0_ptr, st0_tag, (long long __user *)data_address) ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; } return 0; }
void load_store_instr(char type) { FPU_REG *pop_ptr; /* We need a version of FPU_st0_ptr which won't change. */ pop_ptr = NULL; /* Initialized just to stop compiler warnings. */ switch ( type_table[(int) (unsigned) type] ) { case _NONE_: break; case _REG0_: pop_ptr = &st(0); /* Some of these instructions pop after storing */ FPU_st0_ptr = pop_ptr; /* Set the global variables. */ FPU_st0_tag = FPU_st0_ptr->tag; break; case _PUSH_: { pop_ptr = &st(-1); if ( pop_ptr->tag != TW_Empty ) { stack_overflow(); return; } top--; } break; case _null_: return Un_impl(); #ifdef PARANOID default: return EXCEPTION(EX_INTERNAL); #endif PARANOID } switch ( type ) { case 000: /* fld m32real */ reg_load_single(); reg_move(&FPU_loaded_data, pop_ptr); break; case 001: /* fild m32int */ reg_load_int32(); reg_move(&FPU_loaded_data, pop_ptr); break; case 002: /* fld m64real */ reg_load_double(); reg_move(&FPU_loaded_data, pop_ptr); break; case 003: /* fild m16int */ reg_load_int16(); reg_move(&FPU_loaded_data, pop_ptr); break; case 010: /* fst m32real */ reg_store_single(); break; case 011: /* fist m32int */ reg_store_int32(); break; case 012: /* fst m64real */ reg_store_double(); break; case 013: /* fist m16int */ reg_store_int16(); break; case 014: /* fstp m32real */ if ( reg_store_single() ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; case 015: /* fistp m32int */ if ( reg_store_int32() ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; case 016: /* fstp m64real */ if ( reg_store_double() ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; case 017: /* fistp m16int */ if ( reg_store_int16() ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; case 020: /* fldenv m14/28byte */ fldenv(); break; case 022: /* frstor m94/108byte */ frstor(); break; case 023: /* fbld m80dec */ reg_load_bcd(); reg_move(&FPU_loaded_data, pop_ptr); break; case 024: /* fldcw */ RE_ENTRANT_CHECK_OFF control_word = get_fs_word((unsigned short *) FPU_data_address); RE_ENTRANT_CHECK_ON #ifdef NO_UNDERFLOW_TRAP if ( !(control_word & EX_Underflow) ) { control_word |= EX_Underflow; } #endif FPU_data_address = (void *)data_operand_offset; /* We want no net effect */ FPU_entry_eip = ip_offset; /* We want no net effect */ break; case 025: /* fld m80real */ reg_load_extended(); reg_move(&FPU_loaded_data, pop_ptr); break; case 027: /* fild m64int */ reg_load_int64(); reg_move(&FPU_loaded_data, pop_ptr); break; case 030: /* fstenv m14/28byte */ fstenv(); FPU_data_address = (void *)data_operand_offset; /* We want no net effect */ FPU_entry_eip = ip_offset; /* We want no net effect */ break; case 032: /* fsave */ fsave(); FPU_data_address = (void *)data_operand_offset; /* We want no net effect */ FPU_entry_eip = ip_offset; /* We want no net effect */ break; case 033: /* fbstp m80dec */ if ( reg_store_bcd() ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; case 034: /* fstcw m16int */ RE_ENTRANT_CHECK_OFF verify_area(VERIFY_WRITE,FPU_data_address,2); put_fs_word(control_word, (short *) FPU_data_address); RE_ENTRANT_CHECK_ON FPU_data_address = (void *)data_operand_offset; /* We want no net effect */ FPU_entry_eip = ip_offset; /* We want no net effect */ break; case 035: /* fstp m80real */ if ( reg_store_extended() ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; case 036: /* fstsw m2byte */ status_word &= ~SW_TOP; status_word |= (top&7) << SW_TOPS; RE_ENTRANT_CHECK_OFF verify_area(VERIFY_WRITE,FPU_data_address,2); put_fs_word(status_word,(short *) FPU_data_address); RE_ENTRANT_CHECK_ON FPU_data_address = (void *)data_operand_offset; /* We want no net effect */ FPU_entry_eip = ip_offset; /* We want no net effect */ break; case 037: /* fistp m64int */ if ( reg_store_int64() ) pop_0(); /* pop only if the number was actually stored (see the 80486 manual p16-28) */ break; } }
void vsmextract(int argc, char *argv[]) { TVSMFile f; // VSM file TVSMResource m; // processed resource char *fdir; // working directory char *fn; // filename int resno = 1; // resource number int x; char ch; char tmp[1024]; // get filename fn = fname(argv[2]); // can't open file or wrong format if (f.open(fn) == 0) errexit("Incorrect VSM file!\n"); // load resources list TVMSLInfo rlist; if (rlist.load() == 0) puts("Can't load 'resources.txt' file!\n"); TVSMInfo *rinfo; // generating output directory name if (argc <= 3) { fdir = new char[strlen(argv[2]) + 6]; strcpy(fdir, argv[2]); removespecialchars(fname(fdir)); strcat(fdir, "_OUT"); } else fdir = argv[3]; x = createdir(fdir); if (x < 0) errexit("Can't create output folder!"); // file information printf("VSM file: %s\n", fn); printf("Output folder: %s\n", fdir); // directory already exists if (x == 0) { puts("\nOutput directory already exist. Files in this folder " "may be overwritten. Continue? (y/N)\n"); ch = getch(); if ((ch != 'y') && (ch != 'Y')) return; } fileinfo(&f.header, f.computeChecksum()); puts(""); // write header into file sprintf(tmp, "%s\\header.bin", fdir); fsave(tmp, &f.header, sizeof(f.header)); // read resources while ( (x = f.read(&m)) > -1 ) { // get resource info if (rlist.find(m.id)) { rinfo = &rlist.get(); printf("resource %2d: 0x%04X 0x%04X (%s) - %s\n", resno, m.id, m.size, rinfo->ext, rinfo->descr); sprintf(tmp, "%s\\res%04X_%s.%s", fdir, m.id, rinfo->descr, rinfo->ext); } // there is no such resource on the list else { printf("resource %2d: 0x%04X 0x%04X (??\?) - UNKNOWN\n", resno, m.id, m.size); sprintf(tmp, "%s\\res%04X.bin", fdir, m.id); } if (fsave(tmp, m.data, m.size) == 0) printf("Can't write file '%s'!", tmp); delete [] m.data; resno++; } // error during resource read if (x < -1) errexit("Incorrect VSM file!\n"); // if footer exists if (f.footer_sz) { // save footer to file puts(""); sprintf(tmp, "%s\\footer.bin", fdir); if (fsave(tmp, f.footer, f.footer_sz) == 0) puts("Can't write file 'footer.bin'!"); // show footer info footerinfo(f.footer, f.footer_sz); } f.close(); delete [] fdir; }