/** * Launches Awesomenauts, registers the chat binds and listens for key events. */ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { Process* awsmProcess = new Process(); // Load the config file data. INIReader* reader = new INIReader(BLABL_CONFIG); if (reader->ParseError() < 0) { std::cerr << "ERROR: Failed to parse config file." << std::endl; return 1; } // Launch Awesomenauts. const char* awsmBin = reader->Get("Awesomenauts", "Bin", DEFAULT_BIN).c_str(); const char* awsmDir = reader->Get("Awesomenauts", "Dir", DEFAULT_DIR).c_str(); if (!awsmProcess->Launch(awsmBin, awsmDir)) { std::cerr << "ERROR: Failed to create process." << std::endl; return 1; } // Load the bindings and listen for hot key presses while Awesomenauts runs. KeyListener* awsmListener = new KeyListener(GetKeyboardLayout(0)); awsmListener->LoadFromFile(reader); delete reader; while (awsmProcess->IsRunning()) awsmListener->ProcessInput(); delete awsmProcess; delete awsmListener; return 0; }
// Write scores to a file void ScoreBoard::writeScore(std::string s){ INIReader r; // Write current score to a new INI file. for ( auto i = scores.begin(); i != scores.end(); i++){ r.writeParameterValue(i->name, "score", std::to_string(i->score) ); } r.write(s); }
void AcceleratorConfig::populate(INIReader &reader) { datDirectory_ = reader.Get("accelerator", "dat_directory", "~"); nElectrodes_ = reader.GetInteger("accelerator", "n_electrodes", 36); PAname_ = reader.Get("accelerator", "pa_name", "cylinder"); x_ = reader.GetInteger("accelerator", "x", 54) - 2; y_ = reader.GetInteger("accelerator", "y", 54) - 2; z_ = reader.GetInteger("accelerator", "z", 200) - 2; }
int parseIni(void) { cout << "Make sure to have sufficient rights!" << endl; if (reader.ParseError() < 0) cout << "Can't load 'config.ini'\nNow using defaults!\n"; server = reader.Get("private", "SERVER", "tcp://127.0.0.1:3306"); user = reader.Get("private", "USER", "root"); password = reader.Get("private", "PASSWORD", ""); database = reader.Get("private", "DATABASE", "htcpcp"); return 0; }
/* mtree INI checking */ bool iniSettingsAreLegal(INIReader & iniReader, const mt::INIValueChecker & ivc, std::ostream &err) { try { std::string value = iniReader.Get("action", "action", "LScore"); ivc.parseActionAction(value); // triggers exception return true; } catch (mt::IllegalINIValueError & e) { err << "INI value error: " << e.what() << "\n"; err.flush(); return false; } }
void ParticlesConfig::populate(INIReader &reader) { nParticles_ = static_cast<int>(reader.GetReal("particles", "n_particles", 50000)); k_ = reader.GetInteger("particles", "k", 20); kDist_ = reader.Get("particles", "k_dist", "single"); if (kDist_ != "single" && kDist_ != "uniform" && kDist_ != "triangle") { try { throw "Invalid k distribution value!"; } catch (const char* e) { std::cout << e << std::endl; std::terminate(); } } n_ = reader.GetInteger("particles", "n", 25); positionDist_ = reader.Get("particles", "position_dist", "full"); distRadius_ = (float) reader.GetReal("particles", "dist_radius", 0.5); distLength_ = (float) reader.GetReal("particles", "dist_length", 5); distOffset_ = (float) reader.GetReal("particles", "dist_offset", 22); temperature_ = (float) reader.GetReal("particles", "temperature", 1.0); }
void SimulationConfig::populate(INIReader &reader) { accelerationScheme_ = reader.Get("simulation", "accel_scheme", "trap"); if (accelerationScheme_ != "exponential" && accelerationScheme_ != "trap" && accelerationScheme_ != "instantaneous") { try { throw "Invalid value for acceleration scheme!"; } catch (const char* e) { std::cout << e << std::endl; std::terminate(); } } trapShakeTime_ = (float) reader.GetReal("simulation", "trap_shake_time", 1e-6); duration_ = (float) reader.GetReal("simulation", "duration", 6e-4); inglisTeller_ = reader.GetBoolean("simulation", "inglis_teller", false); maxVoltage_ = (float) reader.GetReal("simulation", "max_voltage", 100); targetVel_ = (float) reader.GetReal("simulation", "target_vel", 500); timeStep_ = (float) reader.GetReal("simulation", "time_step", 1e-6); }
void GameConfiguration::runPatchByIni(INIReader& reader) { if (reader.ParseError() != 0) return; gameCharacters::marioGame = reader.Get("game-characters", "mario-game", gameCharacters::marioGame); gameCharacters::luigiGame = reader.Get("game-characters", "luigi-game", gameCharacters::luigiGame); gameCharacters::peachGame = reader.Get("game-characters", "peach-game", gameCharacters::peachGame); gameCharacters::toadGame = reader.Get("game-characters", "toad-game", gameCharacters::toadGame); gameCharacters::linkGame = reader.Get("game-characters", "link-game", gameCharacters::linkGame); mainMenu::player1Game = reader.Get("main-menu", "player1-game", mainMenu::player1Game); mainMenu::player2Game = reader.Get("main-menu", "player2-game", mainMenu::player2Game); mainMenu::battleGame = reader.Get("main-menu", "battle-game", mainMenu::battleGame); mainMenu::options = reader.Get("main-menu", "options", mainMenu::options); mainMenu::exit = reader.Get("main-menu", "exit", mainMenu::exit); optionsMenu::player1Controls = reader.Get("option-menu", "player1-controls", optionsMenu::player1Controls); optionsMenu::player2Controls = reader.Get("option-menu", "player2-controls", optionsMenu::player2Controls); optionsMenu::fullscreenMode = reader.Get("option-menu", "fullscreen-mode", optionsMenu::fullscreenMode); optionsMenu::windowedMode = reader.Get("option-menu", "windowed-mode", optionsMenu::windowedMode); optionsMenu::viewCredits = reader.Get("option-menu", "view-credits", optionsMenu::viewCredits); // References the same string memory, so do not destruct those. general::gameTitle_1.assignNoDestruct(reader.Get("general", "game-title", general::gameTitle_1)); general::gameTitle_2.assignNoDestruct(reader.Get("general", "game-title", general::gameTitle_2)); general::gameTitle_3.assignNoDestruct(reader.Get("general", "game-title", general::gameTitle_3)); }
int main(int argc, char** argv) { if ( argc < 2 ) { fprintf(stderr, "Usage: %s [OPTIONS]\n", argv[0]); fprintf(stderr, "Opions:\n"); fprintf(stderr, "\t-t [TRACE_FILE]+\n"); fprintf(stderr, "\t-s [INI FILE]+\n"); fprintf(stderr, "\t\"Override ini setting\" <section>:<option>:<value>\n"); exit(-1); } sCmdOptions* options = new sCmdOptions; parseCmdLine(argc, argv, options); INIReader* reader = new INIReader(); settings = reader; setDefaults(settings); //Add static defaults settings->addOverwriteException("Processes"); pidGen = new cIDManager(0); vector<string>::iterator it; it = options->settingFiles.begin(); /* Parse all the given settings files into the reader */ for (; it != options->settingFiles.end(); ++it) { cout << "Loading settings file: " << *it << endl; reader->load_ini(*it); } vector<sProc*> processes; it = options->traceFiles.begin(); /* Load all the process traces */ for (; it != options->traceFiles.end(); ++it) { processes.push_back(loadProc(*it)); if ( processes.back() == NULL ) exit(-1); } stringstream settingsProc; //string settingsProc; string procName; /* Load processes specified in the settings files */ for ( int i = 0; i < MAX_SETTINGS_PROCS; ++i) { settingsProc.str(""); settingsProc << i; if( !reader->exists("Processes", settingsProc.str()) ) break; //Get process 'i' from the settings file procName = reader->extractValue<string>("Processes", settingsProc.str()); processes.push_back(loadProc(procName)); if ( processes.back() == NULL ) { cout << "Loaded " << i << " processes from settings file/s" << endl; exit(-1); } } vector<sOpOverride*>::iterator ito; ito = options->overrides.begin(); sOpOverride* to; //Temp override for (; ito != options->overrides.end(); ++ito) { to = *ito; if ( !reader->overWriteOp(to->section, to->option, to->newValue) ) { cerr << "Failed to override setting, likely doesn't exist: " << endl; cerr << "\tSection: " << to->section << endl; cerr << "\tOption: " << to->option << endl; cerr << "\tValue: " << to->newValue << endl; } delete to; } delete options; /* Must initialize the log after all settings files * have been loaded. */ initLog(EXTRACTP(string, Results, trace).c_str()); logStream = getStream(); /* Start up the VMM */ try { cPRPolicy* pr_policy = NULL; cFrameAllocPolicy* fa_policy = NULL; cCleanDaemon* cDaemon = NULL; string FA_Type = EXTRACTP(string, Policy, FA); string PR_Type = EXTRACTP(string, Policy, PR); if ( FA_Type.compare("fixed") == 0 ) { fa_policy = new cFixedAlloc(); } else { cerr << "Invalid Frame Allocator Type: " << FA_Type << endl; exit(-1); } assert(fa_policy != NULL); if ( PR_Type.compare("fifo") == 0 ) { pr_policy = new cPRFifo(*fa_policy); } else if( PR_Type.compare("lru") == 0) { pr_policy = new cPRLru(*fa_policy); } else if ( PR_Type.compare("lru_approx") == 0 ) { pr_policy = new cPRLruApprox(*fa_policy); } else { cerr << "Invalid Page Replacement Type: " << PR_Type << endl; exit(-1); } assert(pr_policy != NULL); cDaemon = new cCleanDaemon(*fa_policy); cVMM* manager = new cVMM(processes, *pr_policy, *cDaemon); manager->start(); } catch ( cVMMExc& error) { cout << "Caught VMM core error: " << endl; cout << "\tError Msg: " << error.getErrorStr() << endl; cout << "\tInfo Dump: " << error.getDump() << endl; closeLog(); exit(-1); } catch ( cException& error ) { cout << "Caught Exception: " << endl; cout << "\tErr Msg: " << error.getErrorStr() << endl; closeLog(); exit(-1); } closeLog(); return 0; }
int do_main(int argc, char *argv[]) { NxsReader::setNCLCatchesSignals(true); MultiFormatReader::DataFormatType f(MultiFormatReader::NEXUS_FORMAT); std::string iniFilename; INIReader * iniReader = nullptr; for (int i = 1; i < argc; ++i) { const char * filepath = argv[i]; const unsigned slen = strlen(filepath); if (slen < 2 || filepath[0] != '-') { continue; } if (filepath[1] == 'h') { printHelp(cout); return 1; } else if (filepath[1] == 'q') { gQuietMode = true; } else if (filepath[1] == 'x') { gValidateInternals = false; } else if (filepath[1] == 'f') { f = MultiFormatReader::UNSUPPORTED_FORMAT; if (slen > 2) { std::string fmtName(filepath + 2, slen - 2); f = MultiFormatReader::formatNameToCode(fmtName); if (f == MultiFormatReader::UNSUPPORTED_FORMAT) { cerr << "Unknown format \"" << fmtName << "\" after -f\n" << endl; printHelp(cerr); return 3; } } if (f == MultiFormatReader::UNSUPPORTED_FORMAT) { cerr << "Expecting a format after -f\n" << endl; printHelp(cerr); return 2; } } else if (filepath[1] == 'm') { if (slen > 2) { if (!iniFilename.empty()) { cerr << "Expecting one INI file with a -m flag.\n"; return 5; } iniFilename.assign(filepath + 2, slen - 2); iniReader = new INIReader(iniFilename.c_str()); if (iniReader->ParseError() < 0) { std::cerr << "Can't load \"" << iniFilename << "\"\n"; return 6; } if (!preDataINICheck(*iniReader, std::cerr)) { std::cerr << "Exiting due to errors in \"" << iniFilename << "\"\n"; return 7; } } else { cerr << "Expecting an INI filepath after the -m flag\n"; return 4; } } } if (iniReader == nullptr) { cerr << "Expecting an INI file specified with a -m flag\n"; return 8; } bool readfile = false; for (int i = 1; i < argc; ++i) { const char * filepath = argv[i]; const unsigned slen = strlen(filepath); if (slen < 1) continue; if (strlen(filepath) > 2 && filepath[0] == '-' && filepath[1] == 'l') { readfile = true; int rc = readFilesListedIsFile(filepath+2, f, *iniReader); if (rc != 0) { return rc; } } else if (filepath[0] != '-') { readfile = true; int rc = readFilepathAsNEXUS(filepath, f, *iniReader); if (rc != 0) { return rc; } } } if (!readfile) { cerr << "Expecting the path to NEXUS file as the only command line argument!\n" << endl; printHelp(cerr); return 1; } return 0; }
void StorageConfig::populate(INIReader &reader) { storeCollisions_ = reader.GetBoolean("storage", "store_collisions", true); storeTrajectories_ = reader.GetBoolean("storage", "store_trajectories", true); compression_ = reader.GetInteger("storage", "compression", 0); }
int main(int argc, char *argv[]) { int InputId = 0; int OutputId = 0; int Opt = 0; OutputInstruments = false; ExCommands = false; DMFConverter * dmf; ESFOutput * esf; INIReader * ini; fprintf(stdout, "\nDMF2ESF ver %d.%d (built %s %s)\n", MAJORVER, MINORVER, __DATE__, __TIME__); fprintf(stdout, "Copyright 2013-2014 ctr.\n"); fprintf(stdout, "Licensed under GPLv2, see LICENSE.txt.\n\n"); fprintf(stdout, "Includes source from Secret Rabbit Code, Licensed under GPLv1, see libsamplerate\COPYING.\n\n"); // fprintf(stdout, "Not licensed under any license;\nyou may not do anything at all with this program.\n\n"); int instrumentIdxOffset = 0; if(argc > 1) { for(int i = 0; i < argc; ++i) { //printf( "argument %d = %s\n", i, argv[i] ); /* Check for options */ Opt = strcmp(argv[i], "-i"); if(!Opt) { OutputInstruments = true; continue; } Opt = strcmp(argv[i], "-a"); if(!Opt) { ASMOut = true; continue; } Opt = strcmp(argv[i], "-e"); if(!Opt) { ExCommands = true; continue; } Opt = strcmp(argv[i], "-instroffset"); if(!Opt) { i++; if(i < argc) { instrumentIdxOffset = atoi(argv[i]); } continue; } if(OutputId == 0) { if(InputId > 0) OutputId = i; if(InputId == 0) InputId = i; } } } if(InputId == 0) // no input file? { //print usage and exit fprintf(stderr, "Usage: dmf2esf <options> input <output>\n"); fprintf(stderr, "Options:\n"); fprintf(stderr, "\t-i : Output FM instrument data\n"); fprintf(stderr, "\t-a : Output ESF as an assembly file\n"); fprintf(stderr, "\t-e : Use EchoEx extended commands\n"); fprintf(stderr, "Please read \"readme.md\" for further usage instructions.\n"); for(int a=0; a<12*7; a++) { fprintf(stderr, "%d\n", fmfreq(a)); } } else { const char *dot = strrchr(argv[InputId], '.'); if(strcmp(dot,".ini") == 0) { fprintf(stdout, "Loading ini: %s\n",argv[InputId]); ini = new INIReader(argv[InputId]); if (ini->ParseError() < 0) { fprintf(stderr, "Failed to load ini: %s\n",argv[InputId]); return EXIT_FAILURE; } bool SearchFlag=true; int TrackIndex=0; char IniSection[64]; string input; while(SearchFlag) { sprintf(IniSection,"%d",TrackIndex); fprintf(stdout, "======== Reading [%s] ========\n",IniSection); string input = ini->Get(IniSection,"input",""); if(input.length() > 0) { if(input.rfind(".") < 0) { fprintf(stderr, "Silly input\n"); return EXIT_FAILURE; } string output = ini->Get(IniSection,"output",""); bool TrackSFX = ini->GetBoolean(IniSection,"sfx",false); if(output.length() == 0) output = input.substr(0,input.rfind(".")); if(output.rfind(".") < 0) { fprintf(stderr, "Silly output\n"); return EXIT_FAILURE; } fprintf(stderr, "Converting %s to %s\n",input.c_str(), output.c_str()); esf = new ESFOutput(output); dmf = new DMFConverter(&esf); FindInstruments(IniSection,ini,dmf); if(dmf->Initialize(input.c_str())) { fprintf(stderr, "Failed to initialize, aborting\n"); break; } if(dmf->Parse()) { fprintf(stderr, "Conversion failed, aborting\n"); break; } fprintf(stdout, "Successfully converted, continuing.\n"); delete esf; delete dmf; } else { //fprintf(stderr, "invalid input '%s' (%d)\n",input.c_str(), input.length()); break; } TrackIndex++; } delete ini; } else { esf = new ESFOutput(string(argv[OutputId])); dmf = new DMFConverter(&esf); esf->InstrumentOffset = instrumentIdxOffset; dmf->InstrumentOffset = instrumentIdxOffset; if(dmf->Initialize(argv[InputId])) { fprintf(stderr, "Aborting\n"); return EXIT_FAILURE; } if(dmf->Parse()) { fprintf(stderr, "Conversion aborted.\n"); return EXIT_FAILURE; } delete dmf; delete esf; } } return EXIT_SUCCESS; }
int main(int argc, char* argv[]) { if (argc != 2) { //get base filename not full argv[0] path char *filePath = strrchr(argv[0], '\\'); string trueName = filePath; trueName.erase(0, 1); cout << "Bot Cannot start\n" "Logon details are loaded from an ini file\n\n" "Usage: "<< trueName <<" [file.ini]\r\n" "An example file has been created for you\r\nAlong with an example batch script to start the bot properly" << endl; string iniFile = "example.ini"; string batch = "runBot.bat"; //deletes preexisting example file remove(iniFile.c_str()); remove(batch.c_str()); //creates a super basic ini filee ofstream iniStream; iniStream.open(iniFile.c_str(), ios::out | ios::app | ios::binary); iniStream << "[LOGON]\r\n" "#your palringo logon details\r\n" "[email protected]\r\n" "password=123456\r\n" "REQUIRED it's used in one or two applications currently to prevent the bot 'talking to itself'\r\n" "botId=123456\r\n" "#SSL yes or no\r\n" "HTTPS=no\r\n\r\n" "[SETTINGS]\r\n" "#the user ID of the user in chage of the bot\r\n" "adminId=1234\r\n\n" "#A plain text name for the admin\r\n" "adminName=myName\r\n\n" "#A plain text name for the bot to respond tor\n" "botName=ravenclaw\r\n\n" "#the prefix for admin bot commands ie: #join or #leave\r\n" "cmdAdmin=#\r\n\n" "#the prefix for user bot commands ie: /help or /google\r\n" "cmdUser=/\r\n" "#Required for an offical palringo bot turns [#help] into [#rc help]\r\n" "#Namespace can be anything as long as it has no spaces\r\n" "nameSpace=rc\r\n" "#if you delete the namespace field the bot will work as normal ie: '#help'\r\n" "#Please see readme.html for more ini settings" ; iniStream.close(); //creates the batch script iniStream.open(batch.c_str(), ios::out | ios::app | ios::binary); iniStream << trueName << " example.ini"; iniStream.close(); engine.pause(); return 1; } else if(argc == 2) { string iniFile = argv[1]; INIReader reader = INIReader(iniFile); if (reader.ParseError() < 0) { cout << "Can't load " << iniFile << "\n"; return 1; } map<string, string> botSettings; //get LOGON details botSettings["username"] = reader.Get("LOGON", "email", "UNKNOWN"); botSettings["password"] = reader.Get("LOGON", "password", "UNKNOWN"); botSettings["botId"] = reader.Get("LOGON", "botId", "UNKNOWN"); botSettings["HTTPS"] = reader.Get("LOGON", "SSL", "true"); //get bot settings botSettings["botAdmin"] = reader.Get("SETTINGS", "adminId", "UNKNOWN"); botSettings["adminName"] = reader.Get("SETTINGS", "adminName", "UNKNOWN"); botSettings["botName"] = reader.Get("SETTINGS", "botName", "UNKNOWN"); botSettings["cmdAdmin"] = reader.Get("SETTINGS", "cmdAdmin", "#"); botSettings["cmdUser"] = reader.Get("SETTINGS", "cmdUser", "/"); botSettings["nameSpace"] = reader.Get("SETTINGS", "nameSpace", "UNKNOWN"); #ifdef RAVENCLAW_DEBUG //obtain user script settings botSettings["useScripts"] = reader.Get("WEBSCRIPTS", "useWebScripts", "false"); botSettings["postUrl"] = reader.Get("WEBSCRIPTS", "postUrl", "UNKNOWN"); #endif //Get the location of the bots ini file botSettings["iniFile"] = iniFile; if(botSettings["username"] == "UNKNOWN" || botSettings["password"] == "UNKNOWN" || botSettings["botAdmin"] == "UNKNOWN" || botSettings["botName"] == "UNKNOWN" || botSettings["adminName"] == "UNKNOWN" || botSettings["botId"] == "UNKNOWN" ) { engine.pl("Bot cannot find required field(s) for logging on\r\nPlease check your .ini file"); engine.pause(); return 1; } #ifdef RAVENCLAW_DEBUG else if(botSettings["useScripts"] != "false" && botSettings["postUrl"] == "UNKNOWN") { engine.pl("You have enabled webScripts but have not supplied a URL please fix this issue."); engine.pause(); return 1; } #endif spinUp(botSettings["botName"]); spinning(botSettings); spinDown(); return 0; } }