bool CodaClientApplication::parseArgument(const QString &a, int argNumber, QString *errorMessage)
{
    switch (argNumber) {
    case 1:
        m_mode = modeArg(a);
        if (m_mode == Invalid) {
            *errorMessage = QLatin1String("Invalid mode");
            return false;
        }
        return true;
    case 2:  { // Address/port
        m_address = a;
        const int colonPos = m_address.indexOf(':');
        if (colonPos != -1) {
            m_port = m_address.mid(colonPos + 1).toUInt();
            m_address.truncate(colonPos);
        }
    }
        break;
    case 3:
        switch (m_mode) {
        case Launch:
            m_launchBinary = fixSlashes(a);
            break;
        case Install:
            m_installSisFile = a;
            break;
        case Uninstall:
            m_uninstallPackage = a.toUInt(0, 0);
            if (!m_uninstallPackage) {
                *errorMessage = QLatin1String("Invalid UID");
                return false;
            }
            break;
        case Put:
            m_putLocalFile = a;
            break;
        case Stat:
            m_statRemoteFile = fixSlashes(a);
            break;
        default:
            break;
        }
        return true;
    case 4:
        switch (m_mode) {
        case Launch:
            m_launchUID = a.toUInt(0, 0);
            if (!m_launchUID) {
                *errorMessage = QLatin1String("Invalid UID");
                return false;
            }
            break;
        case Install:
            m_installTargetDrive = a;
            break;
        case Put:
            m_putRemoteFile = fixSlashes(a);
            break;
        default:
            break;
        }
        return true;

    default:
        if (m_mode == Launch)
            m_launchArgs.push_back(a);
        break;
    }
    return true;
}
Ejemplo n.º 2
0
void LocalInitData::parseArguments( const int argc, char** argv )
{
    try
    {
        std::string wsHelp = "Window System API ( one of: ";
#ifdef AGL
        wsHelp += "AGL ";
#endif
#ifdef GLX
        wsHelp += "glX ";
#endif
#ifdef WGL
        wsHelp += "WGL ";
#endif
        wsHelp += ")";

        const std::string& desc = EqPly::getHelp();

        TCLAP::CmdLine command( desc, ' ', eq::Version::getString( ));
        TCLAP::MultiArg<std::string> modelArg( "m", "model",
                                               "ply model file name or directory",
                                               false, "string", command );
        TCLAP::ValueArg<std::string> portArg( "p", "port",
                                              "tracking device port",
                                              false, "/dev/ttyS0", "string",
                                              command );
        TCLAP::SwitchArg colorArg( "b", "blackAndWhite",
                                   "Don't use colors from ply file",
                                   command, false );
        TCLAP::SwitchArg residentArg( "r", "resident",
                                      "Keep client resident (see resident node documentation on website)",
                                      command, false );
        TCLAP::ValueArg<uint32_t> framesArg( "n", "numFrames",
                                             "Maximum number of rendered frames",
                                             false, 0xffffffffu, "unsigned",
                                             command );
        TCLAP::ValueArg<std::string> wsArg( "w", "windowSystem", wsHelp,
                                            false, "auto", "string", command );
        TCLAP::ValueArg<std::string> modeArg( "c", "renderMode",
                                              "Rendering Mode (immediate, displayList, VBO)",
                                              false, "auto", "string",
                                              command );
        TCLAP::SwitchArg glslArg( "g", "glsl", "Enable GLSL shaders",
                                  command, false );
        TCLAP::SwitchArg invFacesArg( "i", "invertFaces",
                                      "Invert faces (valid during binary file creation)",
                                      command, false );
        TCLAP::ValueArg<std::string> pathArg( "a", "cameraPath",
                                              "File containing camera path animation",
                                              false, "", "string", command );
        TCLAP::SwitchArg overlayArg( "o", "noOverlay", "Disable overlay logo",
                                     command, false );
        TCLAP::VariableSwitchArg ignoreEqArgs( "eq",
                                               "Ignored Equalizer options",
                                               command );
        TCLAP::UnlabeledMultiArg< std::string >
        ignoreArgs( "ignore", "Ignored unlabeled arguments", false, "any",
                    command );
        TCLAP::SwitchArg roiArg( "d", "disableROI", "Disable ROI", command,
                                 false );

        command.parse( argc, argv );

        if( modelArg.isSet( ))
        {
            _filenames.clear();
            _filenames = modelArg.getValue();
        }
        if( portArg.isSet( ))
            _trackerPort = portArg.getValue();
        if( wsArg.isSet( ))
        {
            std::string windowSystem = wsArg.getValue();
            transform( windowSystem.begin(), windowSystem.end(),
                       windowSystem.begin(), (int(*)(int))std::toupper );

            setWindowSystem( windowSystem );
        }

        _color = !colorArg.isSet();

        if( framesArg.isSet( ))
            _maxFrames = framesArg.getValue();

        if( residentArg.isSet( ))
            _isResident = true;

        if( modeArg.isSet() )
        {
            std::string mode = modeArg.getValue();
            transform( mode.begin(), mode.end(), mode.begin(),
                       (int(*)(int))std::tolower );

            if( mode == "immediate" )
                setRenderMode( mesh::RENDER_MODE_IMMEDIATE );
            else if( mode == "displaylist" )
                setRenderMode( mesh::RENDER_MODE_DISPLAY_LIST );
            else if( mode == "vbo" )
                setRenderMode( mesh::RENDER_MODE_BUFFER_OBJECT );
        }

        if( pathArg.isSet( ))
            _pathFilename = pathArg.getValue();

        if( glslArg.isSet() )
            enableGLSL();
        if( invFacesArg.isSet() )
            enableInvertedFaces();
        if( overlayArg.isSet( ))
            disableLogo();
        if( roiArg.isSet( ))
            disableROI();
    }
    catch( const TCLAP::ArgException& exception )
    {
        LBERROR << "Command line parse error: " << exception.error()
                << " for argument " << exception.argId() << std::endl;
        ::exit( EXIT_FAILURE );
    }
}