void FileSelectorWidget::on_FilesEdit_textChanged(QString textChanged) { if (refreshing_) return; // Split current string into separate arguments LineParser parser; parser.getArgsDelim(Parser::UseQuotes, ui.FilesEdit->text()); selectedFilenames_.clear(); for (int n = 0; n < parser.nArgs(); ++n) selectedFilenames_ << parser.argc(n); // If we are updating filter/plugin based on the name, do it here bool formatOk = true; if (updatePluginFromFilename_ && (selectedFilenames_.count() > 0)) formatOk = updatePluginFromCurrentFilename() != NULL; emit(selectionValid((selectedFilenames_.count() > 0) && formatOk)); }
// Parse Simulation block bool SimulationBlock::parse(LineParser& parser, DUQ* duq) { Messenger::print("\nParsing %s block...\n", InputBlocks::inputBlock(InputBlocks::SimulationBlock)); bool blockDone = false, error = false; while (!parser.eofOrBlank(duq->worldPool())) { // Read in a line, which should contain a keyword and a minimum number of arguments parser.getArgsDelim(duq->worldPool(), LineParser::SkipBlanks+LineParser::UseQuotes); SimulationBlock::SimulationKeyword simKeyword = SimulationBlock::keyword(parser.argc(0)); if ((simKeyword != SimulationBlock::nSimulationKeywords) && ((parser.nArgs()-1) < SimulationBlock::nArguments(simKeyword))) { Messenger::error("Not enough arguments given to '%s' keyword.\n", SimulationBlock::keyword(simKeyword)); error = true; break; } switch (simKeyword) { case (SimulationBlock::BoxNormalisationPointsKeyword): duq->setBoxNormalisationPoints(parser.argi(1)); break; case (SimulationBlock::EndSimulationKeyword): Messenger::print("Found end of %s block.\n", InputBlocks::inputBlock(InputBlocks::SimulationBlock)); blockDone = true; break; case (SimulationBlock::MaxIterationsKeyword): duq->setMaxIterations(parser.argi(1)); break; case (SimulationBlock::ParallelStrategyKeyword): if (DUQ::parallelStrategy(parser.argc(1)) == DUQ::nParallelStrategies) { Messenger::error("Unrecognised parallel strategy '%s'.\n", parser.argc(1)); error = true; } else duq->setParallelStrategy(DUQ::parallelStrategy(parser.argc(1))); break; case (SimulationBlock::SeedKeyword): duq->setSeed(parser.argi(1)); break; case (SimulationBlock::WindowFunctionKeyword): if (Data2D::windowFunction(parser.argc(1)) == Data2D::nWindowFunctions) { Messenger::error("Unrecognised window function '%s'.\n", parser.argc(1)); error = true; } else duq->setWindowFunction(Data2D::windowFunction(parser.argc(1))); break; case (SimulationBlock::nSimulationKeywords): Messenger::print("Unrecognised %s block keyword found - '%s'\n", InputBlocks::inputBlock(InputBlocks::SimulationBlock), parser.argc(0)); InputBlocks::printValidKeywords(InputBlocks::SimulationBlock); error = true; break; default: printf("DEV_OOPS - %s block keyword '%s' not accounted for.\n", InputBlocks::inputBlock(InputBlocks::SimulationBlock), SimulationBlock::keyword(simKeyword)); error = true; break; } // Error encountered? if (error) break; // End of block? if (blockDone) break; } return (!error); }
ATEN_USING_NAMESPACE // Load includes void Aten::loadEncoderDefinitions() { Messenger::enter("Aten::loadEncoderDefinitions"); QString encoderDefsFile = dataDirectoryFile("external/encoders.txt"); Messenger::print(Messenger::Verbose, "Looking for encoder definitions (%s)...", qPrintable(encoderDefsFile)); LineParser parser; parser.openInput(encoderDefsFile); if (!parser.isFileGoodForReading()) { Messenger::print("Unable to open encoder definitions file.\n"); return; } // Read in encoder definitions from file QString keyword; EncoderDefinition::EncoderDefinitionKeyword edk; EncoderDefinition* encoder = NULL; ExternalCommand* command = NULL; while (!parser.eofOrBlank()) { // Read first argument from file, which is our keyword parser.getArgsDelim(Parser::SkipBlanks + Parser::StripComments + Parser::UseQuotes); keyword = parser.argc(0); edk = EncoderDefinition::encoderDefinitionKeyword(keyword); if (edk == EncoderDefinition::nEncoderDefinitionKeywords) { Messenger::print("Unrecognised encoder definition keyword '%s'. Ignoring...\n", qPrintable(keyword)); continue; } // Deal with remaining keywords switch (edk) { // Command Name case (EncoderDefinition::CommandNameKeyword): if (!encoder) { Messenger::error("No encoder definition yet created in which to set name data (use 'Name' keyword before all others).\n"); continue; } command = encoder->addCommand(); command->setName(parser.argc(1)); break; // Command case (EncoderDefinition::CommandKeyword): if (!command) { Messenger::error("No command definition yet created in which to set command data (use 'CommandName' keyword before its siblings).\n"); continue; } command->setExecutable(parser.argc(1)); break; // Command arguments case (EncoderDefinition::CommandArgumentsKeyword): if (!command) { Messenger::error("No command definition yet created in which to set argument data (use 'CommandName' keyword before its siblings).\n"); continue; } command->setArguments(parser.argc(1)); break; case (EncoderDefinition::CommandSearchPathsKeyword): if (!command) { Messenger::error("No command definition yet created in which to set searchpath data (use 'CommandName' keyword before its siblings).\n"); continue; } for (int n=1; n<parser.nArgs(); ++n) command->addSearchPath(parser.argc(n)); break; // Name (create new object) case (EncoderDefinition::NameKeyword): encoder = encoders_.add(); encoder->setName(parser.argc(1)); break; case (EncoderDefinition::NicknameKeyword): if (!encoder) { Messenger::error("No encoder definition yet created in which to set data (use 'Name' keyword before all others).\n"); continue; } encoder->setNickname(parser.argc(1)); break; default: break; } } parser.closeFiles(); Messenger::exit("Aten::loadEncoderDefinitions"); }