void CommandLineUtility::parseArguments(QStringList& arguments) { QStringListIterator iter(arguments); QTextStream out(stdout); QTextStream errorsteam(stderr); while (iter.hasNext()) { QString temp = iter.next(); if (helpRegexp.exactMatch(temp)) { helpRequest = true; } else if (versionRegexp.exactMatch(temp)) { versionRequest = true; } else if (trayRegexp.exactMatch(temp)) { launchInTray = true; hideTrayIcon = false; } else if (noTrayRegexp.exactMatch(temp)) { hideTrayIcon = true; launchInTray = false; } else if (loadProfileRegexp.exactMatch(temp)) { if (iter.hasNext()) { temp = iter.next(); QFileInfo fileInfo(temp); if (fileInfo.exists()) { if (fileInfo.suffix() != "xml") { errorsteam << tr("Profile location %1 is not an XML file.").arg(temp) << endl; encounteredError = true; } else { profileLocation = fileInfo.absoluteFilePath(); } } else { errorsteam << tr("Profile location %1 does not exist.").arg(temp) << endl; encounteredError = true; } } } else if (loadProfileForControllerRegexp.exactMatch(temp)) { if (iter.hasNext()) { temp = iter.next(); bool validNumber = false; int tempNumber = temp.toInt(&validNumber); if (validNumber) { controllerNumber = tempNumber; } else if (!temp.isEmpty()) { controllerIDString = temp; } else { errorsteam << tr("Controller identifier is not a valid value.") << endl; encounteredError = true; } } } else if (hiddenRegexp.exactMatch(temp)) { hiddenRequest = true; } } }
void CommandLineUtility::parseArguments(QStringList& arguments) { QStringListIterator iter(arguments); //QTextStream out(stdout); QTextStream errorsteam(stderr); while (iter.hasNext()) { QString temp = iter.next(); if (helpRegexp.exactMatch(temp)) { helpRequest = true; } else if (versionRegexp.exactMatch(temp)) { versionRequest = true; } else if (trayRegexp.exactMatch(temp)) { launchInTray = true; hideTrayIcon = false; } else if (noTrayRegexp.exactMatch(temp)) { hideTrayIcon = true; launchInTray = false; } else if (loadProfileRegexp.exactMatch(temp)) { if (iter.hasNext()) { temp = iter.next(); QFileInfo fileInfo(temp); if (fileInfo.exists()) { if (fileInfo.suffix() != "amgp" && fileInfo.suffix() != "xml") { errorsteam << tr("Profile location %1 is not an XML file.").arg(temp) << endl; encounteredError = true; } else { profileLocation = fileInfo.absoluteFilePath(); } } else { errorsteam << tr("Profile location %1 does not exist.").arg(temp) << endl; encounteredError = true; } } } else if (loadProfileForControllerRegexp.exactMatch(temp)) { if (iter.hasNext()) { temp = iter.next(); bool validNumber = false; int tempNumber = temp.toInt(&validNumber); if (validNumber) { controllerNumber = tempNumber; } else if (!temp.isEmpty()) { controllerIDString = temp; } else { errorsteam << tr("Controller identifier is not a valid value.") << endl; encounteredError = true; } } } else if (hiddenRegexp.exactMatch(temp)) { hiddenRequest = true; } else if (unloadRegexp.exactMatch(temp)) { unloadProfile = true; profileLocation = ""; if (iter.hasNext()) { temp = iter.next(); if (!isPossibleCommand(temp)) { // A value has been passed. Attempt // to validate the value. bool validNumber = false; int tempNumber = temp.toInt(&validNumber); if (validNumber) { controllerNumber = tempNumber; } else if (!temp.isEmpty()) { controllerIDString = temp; } else { errorsteam << tr("Controller identifier is not a valid value.") << endl; encounteredError = true; } } else { // Grabbed a possible command-line option. // Move iterator back to previous item. iter.previous(); } } } else if (startSetRegexp.exactMatch(temp)) { if (iter.hasNext()) { temp = iter.next(); bool validNumber = false; int tempNumber = temp.toInt(&validNumber); if (validNumber && tempNumber >= 1 && tempNumber <= 8) { startSetNumber = tempNumber; } else if (validNumber) { errorsteam << tr("An invalid set number was specified.") << endl; encounteredError = true; } if (iter.hasNext()) { temp = iter.next(); if (!isPossibleCommand(temp)) { if (validNumber) { controllerNumber = tempNumber; } else if (!temp.isEmpty()) { controllerIDString = temp; } else { errorsteam << tr("Controller identifier is not a valid value.") << endl; encounteredError = true; } } else { // Grabbed a possible command-line option. // Move iterator back to previous item. iter.previous(); } } } else { errorsteam << tr("No set number was specified.") << endl; encounteredError = true; } } #ifdef USE_SDL_2 else if (gamepadListRegexp.exactMatch(temp)) { listControllers = true; } else if (mappingRegexp.exactMatch(temp)) { if (iter.hasNext()) { temp = iter.next(); bool validNumber = false; int tempNumber = temp.toInt(&validNumber); if (validNumber) { controllerNumber = tempNumber; mappingController = true; } else if (!temp.isEmpty()) { controllerIDString = temp; mappingController = true; } else { errorsteam << tr("Controller identifier is not a valid value.") << endl; encounteredError = true; } } else { errorsteam << tr("No controller was specified.") << endl; encounteredError = true; } } #endif #ifdef Q_OS_UNIX else if (daemonRegexp.exactMatch(temp)) { daemonMode = true; } #ifdef WITH_X11 else if (displayRegexp.exactMatch(temp)) { if (iter.hasNext()) { displayString = iter.next(); } else { errorsteam << tr("No display string was specified.") << endl; encounteredError = true; } } #endif #endif // Check if this is the last argument. If it is and no command line flag // is active, the final argument is likely a profile that has // been specified. else if (!temp.isEmpty() && !iter.hasNext()) { // If the file exists and it is an xml file, assume that it is a // profile. QFileInfo fileInfo(temp); if (fileInfo.exists()) { if (fileInfo.suffix() != "amgp" && fileInfo.suffix() != "xml") { errorsteam << tr("Profile location %1 is not an XML file.").arg(temp) << endl; encounteredError = true; } else { profileLocation = fileInfo.absoluteFilePath(); } } else { errorsteam << tr("Profile location %1 does not exist.").arg(temp) << endl; encounteredError = true; } } } }