int declarewinner(chess *q) { int n; if(q->state == WHITE) { clear(); init_pair(13, COLOR_WHITE, COLOR_RED); bkgd(COLOR_PAIR(13)); mvprintw(LINES / 2 - 4, COLS /2 - 4, "BLACK WINS"); mvprintw(LINES / 2 - 2, COLS /2 - 6, "Want to resume?"); mvprintw(LINES / 2, COLS /2 - 5,"1. Yes 2. No"); mvprintw(LINES / 2 + 2, COLS /2 - 5, "Enter choice"); curs_set(1); mvscanw(LINES / 2 + 4, COLS /2, "%d", &n); curs_set(0); refresh(); display(stdscr, q); if(n == 1) { undoredo(q, "undo"); undoredo(q, "undo"); display(stdscr, q); return 0; } else { savefile(q); getch(); return 1; } } else { clear(); init_pair(13, COLOR_WHITE, COLOR_RED); bkgd(COLOR_PAIR(13)); mvprintw(LINES / 2 - 4, COLS /2 - 4, "WHITE WINS"); mvprintw(LINES / 2 - 2, COLS /2 - 6, "Want to resume?"); mvprintw(LINES / 2, COLS /2 - 5,"1. Yes 2. No"); mvprintw(LINES / 2 + 2, COLS /2 - 5, "Enter choice"); /* mvprintw(22, 110, "Want to resume?"); */ /* mvprintw(24, 110, "1. Yes 2. No"); */ /* mvprintw(26, 110, "Enter choice"); */ /* mvwaddch(win, 26, 123, ':'); */ curs_set(1); mvscanw(LINES / 2 + 4, COLS / 2, "%d", &n); curs_set(0); refresh(); display(stdscr, q); if(n == 1) { undoredo(q, "undo"); undoredo(q, "undo"); display(stdscr, q); return 0; } else { savefile(q); getch(); return 1; } } }
int main(){ int p,cnt; char fn[10]; FILE *fp; data=malloc(BUFFSIZE*sizeof(double)); den=malloc(DIM*DIM*sizeof(int)); bitmap=malloc(DIM*DIM*3); if(!data||!den||!bitmap){ printf("Out of memory!\n"); exit(-1); } for(p=0;p<8;p++){ sprintf(fn,"r%d.data",p); printf("Loading : %s\n",fn); fp=fopen(fn,"rb"); fseek(fp,0,SEEK_END); //定位到文件尾 cnt=ftell(fp)/sizeof(double)/2; //根据文件大小计算数据量 fseek(fp,0,SEEK_SET); //定位到文件头 fread(data,sizeof(double),2*cnt,fp); fclose(fp); printf("Loaded, count=%d\n",cnt); printf("Processing : %s\n",fn); countroot(cnt); genpic(p); savefile(p); } return 0; }
void MainWindow::savefile() { if(filename.length()!=0) { QFile file(filename); file.open(QIODevice::WriteOnly); QTextStream out(&file); out<<ui->textEdit->toPlainText(); } else { QString fn = QFileDialog::getSaveFileName (this, tr("另存为..."), ".",tr(" (*.c)")); if (!fn.isEmpty()) { if(!fn.endsWith(".c", Qt::CaseInsensitive)) { filename=fn+".c"; } else { filename=fn; } savefile (); } } ui->label->setText(filename); }
int declaredraw(chess *q, char *str) { int n; mvprintw(23, 110, "%s", str); getch(); clear(); init_pair(13, COLOR_WHITE, COLOR_RED); bkgd(COLOR_PAIR(13)); mvprintw(LINES / 2 - 4, COLS /2 - 1, "DRAW"); mvprintw(LINES / 2 - 2, COLS /2 - 6, "Want to resume?"); mvprintw(LINES / 2, COLS /2 - 5,"1. Yes 2. No"); mvprintw(LINES / 2 + 2, COLS /2 - 5, "Enter choice"); curs_set(1); mvscanw(LINES / 2 + 4, COLS /2, "%d", &n); curs_set(0); refresh(); if(n == 1) { undoredo(q, "undo"); undoredo(q, "undo"); display(stdscr, q); return 0; } else { q->enable = DISABLE; savefile(q); return 1; } }
void saveNetworkHeaderFile(NeuralNetwork* nn, const char outputfile[]) { std::ofstream savefile(outputfile); savefile << "float weightIH[" << INPUT_SIZE+1 << "][" << HIDDEN_SIZE << "] = {\n"; for (int i = 0; i < INPUT_SIZE; i++) { savefile << "\t{"; for (int j = 0; j < HIDDEN_SIZE-1; j++) { savefile << nn->weightIH[i][j] << ", "; } savefile << nn->weightIH[i][HIDDEN_SIZE-1] << "},\n"; } savefile << "\t{"; for (int j = 0; j < HIDDEN_SIZE-1; j++) { savefile << nn->weightIH[INPUT_SIZE][j] << ", "; } savefile << nn->weightIH[INPUT_SIZE][HIDDEN_SIZE-1] << "}\n};\n\n"; savefile << "float weightHO[" << HIDDEN_SIZE+1 << "][" << OUTPUT_SIZE << "] = {\n"; for (int i = 0; i < HIDDEN_SIZE; i++) { savefile << "\t{"; for (int j = 0; j < OUTPUT_SIZE-1; j++) { savefile << nn->weightHO[i][j] << ", "; } savefile << nn->weightHO[i][OUTPUT_SIZE-1] << "},\n"; } savefile << "\t{"; for (int j = 0; j < OUTPUT_SIZE-1; j++) { savefile << nn->weightHO[HIDDEN_SIZE][j] << ", "; } savefile << nn->weightHO[HIDDEN_SIZE][OUTPUT_SIZE-1] << "}\n};\n\n"; savefile.close(); }
int _tmain(int argc, _TCHAR* argv[]) { //wurde alles korrekt uebergeben? if(argc < 8||(_tcscmp(argv[1], TEXT("-r")) != 0)|| argv[2]<=0||(_tcscmp(argv[3], TEXT("-o_height")) != 0)|| !(_tcscmp(argv[4], TEXT("")) != 0)|| (_tcscmp(argv[5], TEXT("-o_color")) != 0)|| !(_tcscmp(argv[6], TEXT("")) != 0)|| (_tcscmp(argv[7], TEXT("-o_normal")) != 0)|| !(_tcscmp(argv[8], TEXT("")) != 0)) { std::cout<<"Bitte nur eingaben in folgendem format:\n -r <resolution> -o_height <output heightfield filename>\n -o_color <output color filename> -o_normal <output normal filename>\n"; system("pause"); return 0; } //Variablen const int resolution = _tstoi(argv[2]); std::wstring lowFlat (L"C:\\local\\gep\\external\\textures\\gras15.jpg"); std::wstring lowSteep (L"C:\\local\\gep\\external\\textures\\mud02.jpg"); std::wstring highFlat (L"C:\\local\\gep\\external\\textures\\rock4.jpg"); std::wstring highSteep (L"C:\\local\\gep\\external\\textures\\rock3.jpg"); //diamondsquare starten //DiamondSquare(heightfield, resolution); std::cout << "START" << "\n"; diamondSquare = new DiamondSquare(resolution+1, 0.57, 0., 1.); // heightfield generieren diamondSquare->generate(); // heightfield Smoothen diamondSquare->smooth(10); //heightfield speichern //savefile(argv[4],resolution, diamondSquare->heightfield); // Normal map generieren normalMap = new NormalMap(resolution+1, diamondSquare, argv[8]); normalMap->generate(); normalMap->save(); // generate textures textureGenerator = new TextureGenerator(diamondSquare, normalMap); textureGenerator->generate(); textureGenerator->save(argv[6]); diamondSquare->downsize(); savefile(argv[4],resolution * 0.25, diamondSquare->smallHeightfield); system("pause"); return 0; }
/* makes wav file */ void makewav(const UL rate,const UL dlen){ const UL mlen=dlen+44; UC*const m=malloc(mlen); if(m){ wavhdr(m,rate,dlen); makeaud(m+44,rate,dlen); savefile("out.wav",m,mlen); } }
//---------------------------------------------------------------- void mApp::CheckForUpdateThread() { sleep(10); MSave savefile("savefile"); _mWindow->GetSettingsPath(&path); savefile.FindBool(path, SAVE_FILE_NAME, "CheckForUpdates", &CheckForUpdates, true); if (CheckForUpdates) { tmp.SetTo("wget "); tmp.Append(SAVE_UPDATE_VERSION); tmp.Append(" "); tmp.Append(GET_NEW_VERSION_PATH); tmp.Append(" &"); system(tmp.String()); tmp.SetTo("wget "); tmp.Append(SAVE_UPDATE_URL); tmp.Append(" "); tmp.Append(GET_NEW_URL_PATH); tmp.Append(" &"); system(tmp.String()); sleep(10); FILE* file_version = fopen(SAVE_UPDATE_VERSION, "r"); char version[1024]; fgets(version, sizeof(version), file_version); char version_current[1024]; tmp2.SetTo(""); tmp2 << BUILD_NUMBER; strcpy(version_current, tmp2.String()); if (atoi(version) > atoi(version_current)) { FILE* url = fopen(SAVE_UPDATE_URL, "r"); char mURLToNewFile[1024]; fgets(mURLToNewFile, sizeof(mURLToNewFile), url); switch((new BAlert("BAlertUpdate", STR_A_NEW_VERSION_IS_AVAILABLE[INT_LANGUAGE], STR_NO_NEVER[INT_LANGUAGE], STR_NO[INT_LANGUAGE], STR_YES[INT_LANGUAGE]))->Go()) { //yes case 2: { BString tmp; tmp.SetTo("/boot/beos/apps/NetPositive "); tmp.Append(mURLToNewFile); system(tmp.String()); break; } case 0: savefile.AddBool(path, SAVE_FILE_NAME, NAME_CHECK_FOR_UPDATES, false, true); break; } } } }
int BEE::Room::save_instance_map(std::string fname) { std::ofstream savefile (fname, std::ios::trunc); if (savefile.good()) { for (auto& i : instances) { savefile << i.second->object->get_name() << "," << (int)(i.second->get_xstart()) << "," << (int)(i.second->get_ystart()) << "\n"; } savefile.close(); return 0; } return 1; }
bool MainWindow::save() { QString filename = QFileDialog::getSaveFileName(this, tr("save"), ".", tr("pcap file (*.pcap)")); if(filename.isEmpty()) { return false; } bool status; status = savefile(filename); return status; }
int MainWindow::compile() { savefile(); ui->label->setText("Compiling"); QString command = compiler + "< " + filename + " >" + filename + ".cminus 2>&1"; system(command.toLocal8Bit().data()); ui->label->setText("Done"); QFile file(filename + ".cminus"); file.open( QIODevice::ReadOnly); QString strFileContent; strFileContent = file.readAll(); ui->textEdit_2->clear(); ui->textEdit_2->setText(strFileContent); file.close(); }
void ArtificialPlayer::SaveProgress(char const * File) { for (uint32_t i = 0; i < ga->nXH; i++) { (*Root)["NeuralData"]["W"]["xh"][i] = ga->W_xh[i]; } for (uint32_t i = 0; i < ga->nHH; i++) { (*Root)["NeuralData"]["W"]["hh"][i] = ga->W_hh[i]; } for (uint32_t i = 0; i < ga->nHY; i++) { (*Root)["NeuralData"]["W"]["hy"][i] = ga->W_hy[i]; } for (uint32_t j = 0, i = 0; j < (*Root)["NeuralData"]["Number"].asUInt(); j++, i += (*Root)["NeuralData"]["Layout"][2*j+1].asUInt()) { for (uint32_t k = 0; k < (*Root)["NeuralData"]["Layout"][2*j+1].asUInt(); k++) { (*Root)["NeuralData"]["Memory"][i+k] = ga->GetChromosomes()[0]->NNs[j].h[k]; } } Json::StyledStreamWriter writer; std::ofstream savefile(File); writer.write(savefile, *Root); savefile.close(); }
UINT savedir(char *directory, UINT parent_inode) { initrd_inode inode; initrd_folder_entry *entries; UINT tmp, i = HARDLINKS; DIR *pDIR; struct dirent *pDirEnt; char filename[255]; header.entries++; createinode(directory, &inode, FS_DIRECTORY); fprintf(stderr, "Enter directory %s (inode %d)\n", directory, inode.inode); inode.size = sizeof(initrd_folder_entry) * (count_of_inodes(directory, 0) + HARDLINKS); entries = (initrd_folder_entry *)expand_initrd(inode.size); entries[0].inode = inode.inode; strcpy(entries[0].filename, "."); //HARDLINK auf mich selbst header.entries++; entries[1].inode = (parent_inode == -1) ? inode.inode : parent_inode; //Wenn Wurzelknoten strcpy(entries[1].filename, ".."); //HARDLINK auf Elternknoten header.entries++; pDIR = opendir(directory); if (!pDIR) return -1; pDirEnt = readdir(pDIR); while (pDirEnt) { if (strcmp(".", pDirEnt->d_name) && strcmp("..", pDirEnt->d_name)) { memset(entries[i].filename, 0, INITRD_FILENAME_LEN); strcpy(entries[i].filename, pDirEnt->d_name); strcpy(filename, directory); strcat(filename, "/"); strcat(filename, pDirEnt->d_name); tmp = savefile(filename, pDirEnt->d_type, inode.inode); entries = (initrd_folder_entry *)((UINT)filebuf + inode.offset); entries[i].inode = tmp; i++; } pDirEnt = readdir(pDIR); } closedir(pDIR); inodes[inode.inode] = inode; return inode.inode; }
//--------------------------------------------------------------- int main(int32 argc, char** argv) { //We save the execDir to the settings file BPath path; BString tmp; MSave savefile("savefile"); find_directory(B_COMMON_SETTINGS_DIRECTORY, &path); tmp.SetTo(path.Path()); tmp.Append(SAVE_SETTINGS_PATH); path.SetTo(tmp.String()); tmp.SetTo(argv[0]); tmp.RemoveLast(STR_EXEC_FILE_NAME); savefile.AddString(path, SAVE_FILE_NAME, NAME_EXEC_DIR, tmp.String(), true); new mApp(); be_app->Run(); return(0); }
template <uint32_t D, class Particle> void MonteCarloSimulatorMuVT<D, Particle>::InitializeFromFile(char const * filename) { Json::Value Root; Json::Reader reader; std::ifstream savefile(filename, std::ifstream::in); savefile >> Root; savefile.close(); StepSize = Root["StepSize"].asDouble(); Beta = Root["Beta"].asDouble(); Mu = Root["Mu"].asDouble(); MaxParticlesNumber = Root["MaxParticlesNumber"].asUInt(); TotalSteps = Root["TotalSteps"].asUInt(); SaveSystemInterval = Root["SaveSystemInterval"].asUInt(); SavedSteps = SaveSystemInterval > 0 ? TotalSteps / SaveSystemInterval + 1 : 0; __PostInitialize(Root); }
void ArtificialPlayer::LoadProgress(char const * File) { Root = new Json::Value; Json::Reader reader; std::ifstream savefile(File, std::ifstream::in); savefile >> *Root; savefile.close(); sg = new SnakeGame((*Root)["BoardData"]["Height"].asUInt(),(*Root)["BoardData"]["Width"].asUInt()); sg->Initialize(); uint32_t * nl = new uint32_t[1+2*(*Root)["NeuralData"]["Number"].asUInt()]; for (uint32_t i = 0; i < 1+2*(*Root)["NeuralData"]["Number"].asUInt(); i++) { nl[i] = (*Root)["NeuralData"]["Layout"][i].asUInt(); } ga = new GeneticAlgorithm( (*Root)["GeneticData"]["Selection"].asUInt(), (*Root)["NeuralData"]["Number"].asUInt(), nl, std::function<double(RNN&)>( std::bind(&ArtificialPlayer::RNNFitness, this, std::placeholders::_1) ), (*Root)["GeneticData"]["MutRate"].asUInt() ); for (uint32_t i = 0; i < ga->nXH; i++) { ga->W_xh[i] = (*Root)["NeuralData"]["W"]["xh"][i].asDouble(); } for (uint32_t i = 0; i < ga->nHH; i++) { ga->W_hh[i] = (*Root)["NeuralData"]["W"]["hh"][i].asDouble(); } for (uint32_t i = 0; i < ga->nHY; i++) { ga->W_hy[i] = (*Root)["NeuralData"]["W"]["hy"][i].asDouble(); } double * mem = new double[ga->nH]; for (uint32_t j = 0, i = 0; j < (*Root)["NeuralData"]["Number"].asUInt(); j++, i += (*Root)["NeuralData"]["Layout"][2*j+1].asUInt()) { for (uint32_t k = 0; k < (*Root)["NeuralData"]["Layout"][2*j+1].asUInt(); k++) { mem[i+k] = (*Root)["NeuralData"]["Memory"][i+k].asDouble(); } } ga->InitializeLoad(mem); delete[] mem; }
void saveNetwork(NeuralNetwork* nn, const char outputfile[]) { std::ofstream savefile(outputfile); savefile << INPUT_SIZE << "\n"; savefile << HIDDEN_SIZE << "\n"; savefile << OUTPUT_SIZE << "\n"; for (int i = 0; i < INPUT_SIZE+1; i++) { for (int j = 0; j < HIDDEN_SIZE; j++) { savefile << nn->weightIH[i][j] << "\n"; } } for (int i = 0; i < HIDDEN_SIZE+1; i++) { for (int j = 0; j < OUTPUT_SIZE; j++) { savefile << nn->weightHO[i][j] << "\n"; } } savefile.close(); }
template <uint32_t D, class Particle> void MonteCarloSimulatorMuVT<D, Particle>::SaveParticles(char const * filename) { Json::Value Root; Root["Dimensions"] = D; Root["SavedSteps"] = SavedSteps; Root["MaxParticlesNumber"] = MaxParticlesNumber; Root["ParticlesRadius"] = ParticlesRadius; Root["Volume"] = Volume; Root["Beta"] = Beta; Root["Mu"] = Mu; Root["TotalSteps"] = TotalSteps; Root["SaveSystemInterval"] = SaveSystemInterval; for (uint32_t i = 0; i < D; i++) { Root["SystemSize"][0][i] = SystemSize[0][i]; Root["SystemSize"][1][i] = SystemSize[1][i]; } for (uint32_t i = 0; i < SavedSteps; i++) { Root["PartDelta"][i] = StoredStepSize[i]; Root["ParticlesNumber"][i] = StoredParticlesNumber[i]; Root["Density"][i] = StoredDensity[i]; } /* for (uint32_t i = 0; i < SavedSteps; i++) { for (uint32_t j = 0; j < StoredParticlesNumber[i]; j++) { for (uint32_t k = 0; k < D; k++) { Root["Particles"][i][j][k] = StoredParticles[i][j].X[k]; } } } */ __PostSaveParticles(Root); Json::FastWriter writer; std::ofstream savefile(filename); savefile << writer.write(Root); savefile.close(); }
void PokedexData::insert(Advertise* a) { if(!a) return; // deleteItem(a->adid); deleteItemByImgUrl(a->imgurl); if(v_pokedex.empty()) { v_pokedex.push_back(a); } else { uint i = 0; for(; i < v_pokedex.size(); i ++) { if(a->datetime > v_pokedex[i]->datetime) break; } v_pokedex.insert(v_pokedex.begin() + i, a); if(v_pokedex.size() >= POKEDEX_MAX) { vector<Advertise*>::iterator it = v_pokedex.begin() + POKEDEX_MAX; while(it != v_pokedex.end()) { //----删除多余图片----- string filename = ITools::Intercept_string((*it)->imgurl, "/");//截取图片名 string path = FileUtils::getInstance()->getWritablePath() + IMAGE_ROOT_FINDER + "/" + IMAGE_AD_FINDER + "/" + filename; bool del = IFile::removeFile(path); GAMELOG("PokedexData::insert del = %d", del); //----删除存储节点----- SAFE_DELETE(*it); it = v_pokedex.erase(it); } } // GAMELOG("PokedexData::insert time = %llu, v_pokedexsize = %lu", a->datetime, v_pokedex.size()); } savefile(); }
bool GCIFile::LoadSaveBlocks() { if (m_save_data.size() == 0) { if (m_filename.empty()) return false; File::IOFile savefile(m_filename, "rb"); if (!savefile) return false; INFO_LOG(EXPANSIONINTERFACE, "Reading savedata from disk for %s", m_filename.c_str()); savefile.Seek(DENTRY_SIZE, SEEK_SET); u16 num_blocks = BE16(m_gci_header.BlockCount); m_save_data.resize(num_blocks); if (!savefile.ReadBytes(m_save_data.data(), num_blocks * BLOCK_SIZE)) { PanicAlertT("Failed to read data from gci file %s", m_filename.c_str()); m_save_data.clear(); return false; } } return true; }
void ExporterPluginView::exportToFile() { KUrl url = KFileDialog::getSaveUrl(m_view->document()->documentName(), "text/html", m_view, i18n("Export File as HTML")); if ( url.isEmpty() ) { return; } QString filename; if ( url.isLocalFile() ) { filename = url.toLocalFile(); } else { ///TODO: cleanup! don't let the temp files lay around KTemporaryFile tmp; // ### only used for network export tmp.setAutoRemove(false); tmp.open(); filename = tmp.fileName(); } KSaveFile savefile(filename); if (savefile.open()) { QTextStream outputStream ( &savefile ); exportData(false, outputStream); savefile.finalize(); //check error? } // else // {/*ERROR*/} if ( !url.isLocalFile() ) { KIO::NetAccess::upload( filename, url, 0 ); } }
int main(void) { // Parse queries. Q_ENTRY *req = qCgiRequestParse(NULL, 0); // get queries const char *text = req->getStr(req, "text", false); const char *filedata = req->getStr(req, "binary", false); int filelength = req->getInt(req, "binary.length"); const char *filename = req->getStr(req, "binary.filename", false); const char *contenttype = req->getStr(req, "binary.contenttype", false); // check queries if (text == NULL) qCgiResponseError(req, "Invalid usages."); if (filename == NULL || filelength == 0) qCgiResponseError(req, "Select file, please."); char filepath[1024]; sprintf(filepath, "%s/%s", BASEPATH, filename); if (savefile(filepath, filedata, filelength) < 0) { qCgiResponseError(req, "File(%s) open fail. Please make sure CGI or directory has right permission.", filepath); } // result out qCgiResponseSetContentType(req, "text/html"); printf("You entered: <b>%s</b>\n", text); printf("<br><a href=\"%s\">%s</a> (%d bytes, %s) saved.", filepath, filename, filelength, contenttype); // dump printf("\n<p><hr>--[ DUMP INTERNAL DATA STRUCTURE ]--\n<pre>"); req->print(req, stdout, false); printf("\n</pre>\n"); // de-allocate req->free(req); return 0; }
QAction *MainWindow::createAction(const QString icon, const QString toolTip, const QString statusTip, bool scripted) { QAction *ACTION = new QAction(QIcon("icons/" + getSettingsGeneralIconTheme() + "/" + icon + ".png"), toolTip, this); //TODO: Qt4.7 wont load icons without an extension... ACTION->setStatusTip(statusTip); ACTION->setObjectName(icon); // TODO: Set What's This Context Help to statusTip for now so there is some infos there. // Make custom whats this context help popup with more descriptive help than just // the status bar/tip one liner(short but not real long) with a hyperlink in the custom popup // at the bottom to open full help file description. Ex: like wxPython AGW's SuperToolTip. ACTION->setWhatsThis(statusTip); // TODO: Finish All Commands ... <.< if (icon == "donothing") connect(ACTION, SIGNAL(triggered()), this, SLOT(doNothing())); else if(icon == "new") { ACTION->setShortcut(QKeySequence::New); connect(ACTION, SIGNAL(triggered()), this, SLOT(newFile())); } else if(icon == "open") { ACTION->setShortcut(QKeySequence::Open); connect(ACTION, SIGNAL(triggered()), this, SLOT(openFile())); } else if(icon == "save") { ACTION->setShortcut(QKeySequence::Save); connect(ACTION, SIGNAL(triggered()), this, SLOT(savefile())); } else if(icon == "saveas") { ACTION->setShortcut(QKeySequence::SaveAs); connect(ACTION, SIGNAL(triggered()), this, SLOT(saveasfile())); } else if(icon == "print") { ACTION->setShortcut(QKeySequence::Print); connect(ACTION, SIGNAL(triggered()), this, SLOT(print())); } else if(icon == "designdetails") { ACTION->setShortcut(QKeySequence("Ctrl+D")); connect(ACTION, SIGNAL(triggered()), this, SLOT(designDetails())); } else if(icon == "exit") { ACTION->setShortcut(QKeySequence("Ctrl+Q")); connect(ACTION, SIGNAL(triggered()), this, SLOT(exit())); } else if(icon == "cut") { ACTION->setShortcut(QKeySequence::Cut); connect(ACTION, SIGNAL(triggered()), this, SLOT(cut())); } else if(icon == "copy") { ACTION->setShortcut(QKeySequence::Copy); connect(ACTION, SIGNAL(triggered()), this, SLOT(copy())); } else if(icon == "paste") { ACTION->setShortcut(QKeySequence::Paste); connect(ACTION, SIGNAL(triggered()), this, SLOT(paste())); } else if(icon == "windowcascade") connect(ACTION, SIGNAL(triggered()), mdiArea, SLOT(cascade())); else if(icon == "windowtile") connect(ACTION, SIGNAL(triggered()), mdiArea, SLOT(tile())); else if(icon == "windowclose") { ACTION->setShortcut(QKeySequence::Close); connect(ACTION, SIGNAL(triggered()), this, SLOT(onCloseWindow())); } else if(icon == "windowcloseall") connect(ACTION, SIGNAL(triggered()), mdiArea, SLOT(closeAllSubWindows())); else if(icon == "windownext") { ACTION->setShortcut(QKeySequence::NextChild); connect(ACTION, SIGNAL(triggered()), mdiArea, SLOT(activateNextSubWindow())); } else if(icon == "windowprevious") { ACTION->setShortcut(QKeySequence::PreviousChild); connect(ACTION, SIGNAL(triggered()), mdiArea, SLOT(activatePreviousSubWindow())); } else if(icon == "help") connect(ACTION, SIGNAL(triggered()), this, SLOT(help())); else if(icon == "changelog") connect(ACTION, SIGNAL(triggered()), this, SLOT(changelog())); else if(icon == "tipoftheday") connect(ACTION, SIGNAL(triggered()), this, SLOT(tipOfTheDay())); else if(icon == "about") connect(ACTION, SIGNAL(triggered()), this, SLOT(about())); else if(icon == "whatsthis") connect(ACTION, SIGNAL(triggered()), this, SLOT(whatsThisContextHelp())); else if(icon == "icon16") connect(ACTION, SIGNAL(triggered()), this, SLOT(icon16())); else if(icon == "icon24") connect(ACTION, SIGNAL(triggered()), this, SLOT(icon24())); else if(icon == "icon32") connect(ACTION, SIGNAL(triggered()), this, SLOT(icon32())); else if(icon == "icon48") connect(ACTION, SIGNAL(triggered()), this, SLOT(icon48())); else if(icon == "icon64") connect(ACTION, SIGNAL(triggered()), this, SLOT(icon64())); else if(icon == "icon128") connect(ACTION, SIGNAL(triggered()), this, SLOT(icon128())); else if(icon == "settingsdialog") connect(ACTION, SIGNAL(triggered()), this, SLOT(settingsDialog())); else if(icon == "undo") connect(ACTION, SIGNAL(triggered()), this, SLOT(undo())); else if(icon == "redo") connect(ACTION, SIGNAL(triggered()), this, SLOT(redo())); else if(icon == "makelayercurrent") connect(ACTION, SIGNAL(triggered()), this, SLOT(makeLayerActive())); else if(icon == "layers") connect(ACTION, SIGNAL(triggered()), this, SLOT(layerManager())); else if(icon == "layerprevious") connect(ACTION, SIGNAL(triggered()), this, SLOT(layerPrevious())); else if(icon == "textbold") { ACTION->setCheckable(true); connect(ACTION, SIGNAL(toggled(bool)), this, SLOT(setTextBold(bool))); }
QAction *MainWindow::createAction(const QString icon, const QString toolTip, const QString statusTip, bool scripted) { QAction *ACTION = new QAction(QIcon("icons/" + getSettingsGeneralIconTheme() + "/" + icon + ".png"), toolTip, this); //TODO: Qt4.7 wont load icons without an extension... ACTION->setStatusTip(statusTip); ACTION->setObjectName(icon); // TODO: Finish All Commands ... <.< if (icon == "donothing") connect(ACTION, SIGNAL(triggered()), this, SLOT(doNothing())); else if(icon == "new") { ACTION->setShortcut(QKeySequence::New); connect(ACTION, SIGNAL(triggered()), this, SLOT(newfile())); } else if(icon == "open") { ACTION->setShortcut(QKeySequence::Open); connect(ACTION, SIGNAL(triggered()), this, SLOT(openfile())); } else if(icon == "save") { ACTION->setShortcut(QKeySequence::Save); connect(ACTION, SIGNAL(triggered()), this, SLOT(savefile())); } else if(icon == "saveas") { ACTION->setShortcut(QKeySequence::SaveAs); connect(ACTION, SIGNAL(triggered()), this, SLOT(saveasfile())); } else if(icon == "print") { ACTION->setShortcut(QKeySequence::Print); connect(ACTION, SIGNAL(triggered()), this, SLOT(print())); } else if(icon == "close") { ACTION->setShortcut(QKeySequence::Close); connect(ACTION, SIGNAL(triggered()), this, SLOT(onCloseWindow())); } else if(icon == "designdetails") { ACTION->setShortcut(QKeySequence("Ctrl+D")); connect(ACTION, SIGNAL(triggered()), this, SLOT(designDetails())); } else if(icon == "exit") { ACTION->setShortcut(QKeySequence("Ctrl+Q")); connect(ACTION, SIGNAL(triggered()), this, SLOT(exit())); } else if(icon == "cut") { ACTION->setShortcut(QKeySequence::Cut); connect(ACTION, SIGNAL(triggered()), this, SLOT(cut())); } else if(icon == "copy") { ACTION->setShortcut(QKeySequence::Copy); connect(ACTION, SIGNAL(triggered()), this, SLOT(copy())); } else if(icon == "paste") { ACTION->setShortcut(QKeySequence::Paste); connect(ACTION, SIGNAL(triggered()), this, SLOT(paste())); } else if(icon == "windowcascade") connect(ACTION, SIGNAL(triggered()), mdiArea, SLOT(cascade())); else if(icon == "windowtile") connect(ACTION, SIGNAL(triggered()), mdiArea, SLOT(tile())); else if(icon == "windowcloseall") connect(ACTION, SIGNAL(triggered()), mdiArea, SLOT(closeAllSubWindows())); else if(icon == "windownext") { ACTION->setShortcut(QKeySequence::NextChild); connect(ACTION, SIGNAL(triggered()), mdiArea, SLOT(activateNextSubWindow())); } else if(icon == "windowprevious") { ACTION->setShortcut(QKeySequence::PreviousChild); connect(ACTION, SIGNAL(triggered()), mdiArea, SLOT(activatePreviousSubWindow())); } else if(icon == "help") connect(ACTION, SIGNAL(triggered()), this, SLOT(help())); else if(icon == "changelog") connect(ACTION, SIGNAL(triggered()), this, SLOT(changelog())); else if(icon == "tipoftheday") connect(ACTION, SIGNAL(triggered()), this, SLOT(tipOfTheDay())); else if(icon == "about") connect(ACTION, SIGNAL(triggered()), this, SLOT(about())); else if(icon == "aboutQt") connect(ACTION, SIGNAL(triggered()), qApp, SLOT(aboutQt())); else if(icon == "icon16") connect(ACTION, SIGNAL(triggered()), this, SLOT(icon16())); else if(icon == "icon24") connect(ACTION, SIGNAL(triggered()), this, SLOT(icon24())); else if(icon == "icon32") connect(ACTION, SIGNAL(triggered()), this, SLOT(icon32())); else if(icon == "icon48") connect(ACTION, SIGNAL(triggered()), this, SLOT(icon48())); else if(icon == "icon64") connect(ACTION, SIGNAL(triggered()), this, SLOT(icon64())); else if(icon == "icon128") connect(ACTION, SIGNAL(triggered()), this, SLOT(icon128())); else if(icon == "settingsdialog") connect(ACTION, SIGNAL(triggered()), this, SLOT(settingsDialog())); else if(icon == "undo") connect(ACTION, SIGNAL(triggered()), this, SLOT(undo())); else if(icon == "redo") connect(ACTION, SIGNAL(triggered()), this, SLOT(redo())); else if(icon == "makelayercurrent") connect(ACTION, SIGNAL(triggered()), this, SLOT(makeLayerActive())); else if(icon == "layers") connect(ACTION, SIGNAL(triggered()), this, SLOT(layerManager())); else if(icon == "layerprevious") connect(ACTION, SIGNAL(triggered()), this, SLOT(layerPrevious())); else if(icon == "textbold") { ACTION->setCheckable(true); connect(ACTION, SIGNAL(toggled(bool)), this, SLOT(setTextBold(bool))); }
void post(void) { messagerec m; postrec p; char s[121]; int i,dm,a,flag; time_t time1, time2; flag=0; m.storage_type=subboards[curlsub].storage_type; a=0; time1=time(NULL); // write_inst(INST_LOC_POST,curlsub,INST_FLAGS_NONE); // inmsg(&m,p.title,&a,1,(subboards[curlsub].filename),ALLOW_FULLSCREEN, // subboards[curlsub].name, (subboards[curlsub].anony&anony_no_tag)?1:0); savefile(buffer,length,&m,(subboards[curlsub].filename)); if (m.stored_as!=0xffffffff) { p.anony=a; p.msg=m; p.ownersys=0; p.owneruser=usernum; lock_status(); p.qscan=status.qscanptr++; save_status(); time((long *)(&p.daten)); p.status=0; open_sub(1); if ((xsubs[curlsub].num_nets) && (subboards[curlsub].anony & anony_val_net) && (!lcs() || irt[0])) { p.status |= status_pending_net; dm=1; for (i=nummsgs; (i>=1) && (i>(nummsgs-28)); i--) { if (get_post(i)->status & status_pending_net) { dm=0; break; } } if (dm) { sprintf(s,get_stringx(1,37),subboards[curlsub].name); ssm(1,0,s); } } if (nummsgs>=subboards[curlsub].maxmsgs) { i=1; dm=0; while ((dm==0) && (i<=nummsgs)) { if ((get_post(i)->status & status_no_delete)==0) dm=i; ++i; } if (dm==0) dm=1; delete(dm); } add_post(&p); lock_status(); ++status.msgposttoday; ++status.localposts; save_status(); close_sub(); if (xsubs[curlsub].num_nets) { if (!(p.status & status_pending_net)) send_net_post(&p, subboards[curlsub].filename, curlsub); } } }
int main(int argc, char* argv[]){ if(argc != 3){ printf("Useage: input_name output_name"); exit(0); } char file_answer; printf("Select mode:\n" "1.bin to bmp\n" "2.bmp to bmp\n" "3.bin to bin\n"); file_answer=getchar(); fflush(stdin); char *Input=argv[1], *Output=argv[2];//retrive input/output name from commandline BmpHead *pBmpHeader = new BmpHead; unsigned char **pucImageData; char *pcColorMap=NULL; if((file_answer == '1')||(file_answer == '3')){ //read bin file system("cls"); //assign header information courtersy of Lena.bin (*pBmpHeader).bfType=19778; (*pBmpHeader).bfSize=54 + 1024+ 512*512 ; // raw data size = 512*512 = 262144 bytes, modify when necessary (*pBmpHeader).bfReserved=0; (*pBmpHeader).bfOffBits=1078; (*pBmpHeader).biSize=40; (*pBmpHeader).biWidth= 512; //number of columns of the image (*pBmpHeader).biHeight= 512; //number of rows of the image (*pBmpHeader).biPlanes=1; (*pBmpHeader).biBitCount=8; (*pBmpHeader).biCompression=0; (*pBmpHeader).biSizeImage= 512*512; //raw data size = 512*512 = 26144 bytes, modify when necessary, e.g., a 256x256 image: raw data size = 256*256 (*pBmpHeader).biXPelsPerMeter=2834; (*pBmpHeader).biYpelsPerMeter=2834; (*pBmpHeader).biClrUsed=0; (*pBmpHeader).biClrImportant=0; //read provided colormap FILE *colormap=NULL; pcColorMap = new char [1024]; if((colormap=fopen("colormap.bin", "rb")) == NULL){ printf("Failed to find colormap.bin\n"); exit(0); } fread(pcColorMap, sizeof(char), pBmpHeader->bfOffBits-64, colormap); fclose(colormap); //read raw data fron input pucImageData = ReadImage( Input, pBmpHeader->biWidth, 0); printf("successfully read raw data from %s.\n\n", Input); } else if(file_answer == '2'){ //read bmp file system("cls"); //read input header infomation pBmpHeader=ReadBmpHeader(Input); printf("raw data size: %d\n", pBmpHeader->biSizeImage); printf("Image Width: %d\n", pBmpHeader->biWidth); printf("Image Height %d\n", pBmpHeader->biHeight); printf("Header occupies 54 bytes\n"); printf("Color map occupies 1024 bytes\n"); //read input colormap pcColorMap=ReadColorMap(Input, 1024); //read raw data from input //set offset=1024+54 pucImageData=ReadImage(Input, pBmpHeader->biWidth, 1078); printf("successfully read raw data from %s.\n\n", Input); } srand(time(NULL));//plant random seed //function menu char fx_answer; int width, cutoff; do{ printf( "Select function:\n" "A.Turn Lena upside down\n" "B.Turn Lena around\n" "C.Rotate Lena by 45 deg clockwise\n" "D.Shrink Lena by half\n" "E.Invert Lena\n" "F.Add normal noise to Lena\n" "G.Add impluse noise to Lena\n" "H.Moving average filtering\n" "I.Midian filtering\n" "J.Differential flitering\n" "K.LPF\n" "L.HPF\n" "\n0.Exit\n"); printf("Your choice: [_]\b\b"); fx_answer = getchar(); fx_answer = tolower(fx_answer); fflush(stdin); switch(fx_answer){//savefile(): ask user to save as picture or not case 'a':// selected: turn lena upside down UpsideDown(pucImageData, pBmpHeader->biWidth); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'b'://selected: turn lena around LeftRight(pucImageData, pBmpHeader->biWidth); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'c'://selected: rotate lena ImgRotate(pucImageData, pBmpHeader->biWidth, 45); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'd'://selected: shrink lena Shrink(pucImageData, pBmpHeader->biWidth, pBmpHeader, 2); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'e'://selected: invert lena Invert(pucImageData, pBmpHeader->biWidth); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'f'://selected: add noise NormalNoise(pucImageData, pBmpHeader->biWidth); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'g'://selected: add paper n salt noise ImpluseNoise(pucImageData, pBmpHeader->biWidth); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'h'://selected: moving average filter //ask user to input sampling width printf("Enter sampling width:"); scanf("%d", &width); fflush(stdin); MAF(pucImageData, pBmpHeader->biWidth, width); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'i'://selected: moving midian filter //ask user to input sampling width printf("Enter sampling width:"); scanf("%d", &width); fflush(stdin); MF(pucImageData, pBmpHeader->biWidth, width); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'j'://selected: differential filter DIF(pucImageData, pBmpHeader->biWidth); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'k'://selected: low-pass filter //ask user to input cutoff frequency printf("Enter cutoff frenquency(0~%d):", (int)pBmpHeader->biWidth/2); scanf("%d", &cutoff); fflush(stdin); LPF(pucImageData, pBmpHeader->biWidth, cutoff); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case 'l'://selected: high-pass filter //ask user to input cutoff frequency printf("Enter cutoff frenquency(0~%d):", (int)pBmpHeader->biWidth/2); scanf("%d", &cutoff); fflush(stdin); HPF(pucImageData, pBmpHeader->biWidth, cutoff); savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; case '0'://selected: exit //ask one last time whether user want to save or not savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap); break; default: system("cls"); printf("Your choice is not in the list!\n"); break; } if(fx_answer == 0) break;//selected: exit. break the loop } while(fx_answer != '0'); //returning dynamic allocated memory delete [] pcColorMap; delete [] pucImageData; delete pBmpHeader; pcColorMap=NULL; pucImageData=NULL; pBmpHeader=NULL; printf("EOP\n"); }
static int ppdepack(uint8 *data, size_t len, FILE *fo) { /* PP FORMAT: * 1 longword identifier 'PP20' or 'PX20' * [1 word checksum (if 'PX20') $ssss] * 1 longword efficiency $eeeeeeee * X longwords crunched file $cccccccc,$cccccccc,... * 1 longword decrunch info 'decrlen' << 8 | '8 bits other info' */ int success=0; uint8 *output /*, crypted*/; uint32 outlen; if (len < 16) { /*fprintf(stderr, "File is too short to be a PP file (%u bytes)\n", len);*/ return -1; } if (data[0]=='P' && data[1]=='P' && data[2]=='2' && data[3]=='0') { if (len & 0x03) { /*fprintf(stderr, "File length is not a multiple of 4\n");*/ return -1; } /*crypted = 0;*/ } #if 0 else if (data[0]=='P' && data[1]=='X' && data[2]=='2' && data[3]=='0') { if ((len-2) & 0x03) { /*fprintf(stderr, "(file length - 2) is not a multiple of 4\n");*/ return -1; } crypted = 1; } #endif else { /*fprintf(stderr, "File does not have the PP signature\n");*/ return -1; } outlen = (data[len-4]<<16) | (data[len-3]<<8) | data[len-2]; /* fprintf(stderr, "decrunched length = %u bytes\n", outlen); */ output = (uint8 *) malloc(outlen); if (output == NULL) { /*fprintf(stderr, "out of memory!\n");*/ return -1; } /* if (crypted == 0) { */ /*fprintf(stderr, "not encrypted, decrunching anyway\n"); */ if (ppDecrunch(&data[8], output, &data[4], len-12, outlen, data[len-1])) { /* fprintf(stderr, "Decrunch successful! "); */ savefile(fo, (void *) output, outlen); } else { success=-1; } /*} else { success=-1; }*/ free(output); return success; }
template <uint32_t D, class Particle> void MonteCarloSimulatorMuVT<D, Particle>::LoadParticles(char const * filename) { Json::Value Root; Json::Reader reader; std::ifstream savefile(filename, std::ifstream::in); savefile >> Root; savefile.close(); if (Root["Dimensions"].asUInt() != D) { std::cout << "Error: wrong number of dimensions. Should be " << D << " (" << Root["Dimensions"].asUInt() << ")" << std::endl; return; } ParticlesNumber = Root["ParticlesNumber"].asUInt(); ParticlesRadius = Root["ParticlesRadius"].asDouble(); Random.SetRange(0, ParticlesNumber - 1); uint32_t starting_step = Root["SavedSteps"].asUInt() - 1; if (Particles) delete[] Particles; Particles = new Particle[MaxParticlesNumber]; ParticleToAdd = Particles + ParticlesNumber; if (SystemSize) delete[] SystemSize; SystemSize = new Vector<D>[2]; for (uint32_t i = 0; i < D; i++) { SystemSize[0][i] = Root["SystemSize"][0][i].asDouble(); SystemSize[1][i] = Root["SystemSize"][1][i].asDouble(); } Volume = 1.0; HalfSystemSize = SystemSize[1] - SystemSize[0]; for (uint32_t i = 0; i < D; i++) { Volume *= HalfSystemSize[i]; } HalfSystemSize *= 0.5; Density = ParticlesNumber / Volume; for (uint32_t i = 0; i < ParticlesNumber; i++) { for (uint32_t j = 0; j < D; j++) { Particles[i].X[j] = Root["Particles"][starting_step][i][j].asDouble(); } } if (StoredParticles) { for (uint32_t i = 0; i < SavedSteps; i++) { delete[] StoredParticles[i]; } delete[] StoredParticles; } StoredParticles = new Particle*[SavedSteps]; if (StoredStepSize) { delete[] StoredStepSize; } StoredStepSize = new double[SavedSteps]; if (StoredDensity) { delete[] StoredDensity; } StoredDensity = new double[SavedSteps]; if (StoredParticlesNumber) { delete[] StoredParticlesNumber; } StoredParticlesNumber = new uint32_t[SavedSteps]; __PostLoadParticles(Root); }
void Save() { ofstream myfile ("PlayerCharacter.txt"); if (myfile.is_open()) { Combatant *temp; temp = PC->GetStats(); temp->SetExp(PC->GetExperience()); myfile << PC->GetName(); myfile << "\n"; myfile << PC->GetDesc(); myfile << "\n"; myfile << PC->GetLevel(); myfile << "\n"; myfile << PC->GetPrimeStat(); myfile << "\n"; myfile << PC->GetSecondStat(); myfile << "\n"; myfile << PC->GetCurrentRoom()->GetRoomId(); myfile << "\n"; myfile << temp->GetMaxHp(); myfile << "\n"; myfile << temp->GetMaxMp(); myfile << "\n"; myfile << temp->GetMaxStr(); myfile << "\n"; myfile << temp->GetMaxAgi(); myfile << "\n"; myfile << temp->GetMaxAs(); myfile << "\n"; myfile << temp->GetHp(); myfile << "\n"; myfile << temp->GetMp(); myfile << "\n"; myfile << temp->GetStr(); myfile << "\n"; myfile << temp->GetAgi(); myfile << "\n"; myfile << temp->GetAs(); myfile << "\n"; myfile << temp->GetExp(); myfile << "\n"; myfile << PC->GetEqHp(); myfile << "\n"; myfile << PC->GetEqMp(); myfile << "\n"; myfile << PC->GetEqAgi(); myfile << "\n"; myfile << PC->GetEqStr(); myfile << "\n"; myfile << PC->GetEqAs(); myfile.close(); //ifstream myfile ("NPC.txt"); ofstream savefile ("NPCload.txt"); string line; if (savefile.is_open()) { for(int a = 0; a < World::GetInstance()->RoomCount(); a++) { if(World::GetInstance()->GetRooms()[a]->NpcList().size() > 0) { for(int b = 0; b < World::GetInstance()->GetRooms()[a]->NpcList().size(); b++) { if(World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetLife() == "") { World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->SetLife("A"); } savefile << World::GetInstance()->GetRooms()[a]->GetNumNpc() << "\n"; savefile << World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetLife() << "\n"; savefile << World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetMaxHp() << "\n"; savefile << World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetMaxMp() << "\n"; savefile << World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetMaxStr() << "\n"; savefile << World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetMaxAgi() << "\n"; savefile << World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetMaxAs() << "\n"; savefile << World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetHp() << "\n"; savefile << World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetMp() << "\n"; savefile << World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetStr() << "\n"; savefile << World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetAgi() << "\n"; savefile << World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetAs() << "\n"; savefile << World::GetInstance()->GetRooms()[a]->NpcList()[b].GetStats()->GetExp() << "\n" << "\n"; } } } savefile.close(); } cout << endl << "Save Completed" << endl << endl; } else cout << "Unable to open file. Save failed."; }
int saveufile(const std::string& filename, const std::wstring& content){ std::string utf8line; utf8::utf16to8(content.begin(), content.end(), back_inserter(utf8line)); return savefile(filename,utf8line); }