bool getAttrib(const TiXmlElement* XMLNode, const gkString& attrib, UTuint32& value) { if (!XMLNode || !XMLNode->Attribute(attrib)) return false; value = parseUInt(XMLNode->Attribute(attrib.c_str())); return true; }
/** \brief parse option from configuration file. * * \param[in,out] as Pointer to session handle * \param[in] opt name of option to set (left of =) * \param[in] param name of value for option (right of =) * \param type type for param, currently unused * \return 0 if parsing was successful, -1 if an error occured. currently * always returns 0 */ PRIVATE int set_option(auto_handle *as, const char *opt, const char *param, option_type type) { int32_t numval; dbg_printf(P_INFO2, "%s=%s (type: %d)", opt, param, type); assert(as != NULL); if(!strcmp(opt, "url")) { getFeeds(&as->feeds, param); } else if(!strcmp(opt, "feed")) { parseFeed(&as->feeds, param); } else if(!strcmp(opt, "download-folder")) { set_path(param, &as->download_folder); } else if(!strcmp(opt, "statefile")) { set_path(param, &as->statefile); } else if(!strcmp(opt, "interval")) { numval = parseUInt(param); if(numval > 0) { as->check_interval = numval; } else if(numval != -1) { dbg_printf(P_ERROR, "Interval must be 1 minute or more, reverting to default (%dmin)\n\t%s=%s", AM_DEFAULT_INTERVAL, opt, param); } else { dbg_printf(P_ERROR, "Unknown parameter: %s=%s", opt, param); } } else if(!strcmp(opt, "patterns")) { addPatterns_old(&as->filters, param); } else if(!strcmp(opt, "filter")) { parseFilter(&as->filters, param); } else if(!strcmp(opt, "prowl-apikey")) { as->prowl_key = am_strdup(param); } else if(!strcmp(opt, "download-done-script")) { as->download_done_script = am_strdup(param); } else { dbg_printf(P_ERROR, "Unknown option: %s", opt); } return 0; }
bool getValue(const TiXmlElement* XMLNode, UTuint32& value) { if (!XMLNode || !XMLNode->GetText()) return false; value = parseUInt(XMLNode->GetText()); return true; }
void RenderState::StateBlock::setState(const std::string& name, const std::string& value) { if (name.compare("blend") == 0) { setBlend(parseBoolean(value)); } else if (name.compare("blendSrc") == 0) { setBlendSrc(parseBlend(value)); } else if (name.compare("blendDst") == 0) { setBlendDst(parseBlend(value)); } else if (name.compare("cullFace") == 0) { setCullFace(parseBoolean(value)); } else if (name.compare("cullFaceSide") == 0) { setCullFaceSide(parseCullFaceSide(value)); } else if (name.compare("frontFace") == 0) { setFrontFace(parseFrontFace(value)); } else if (name.compare("depthTest") == 0) { setDepthTest(parseBoolean(value)); } else if (name.compare("depthWrite") == 0) { setDepthWrite(parseBoolean(value)); } else if (name.compare("depthFunc") == 0) { setDepthFunction(parseDepthFunc(value)); } else if (name.compare("stencilTest") == 0) { setStencilTest(parseBoolean(value)); } else if (name.compare("stencilWrite") == 0) { setStencilWrite(parseUInt(value)); } else if (name.compare("stencilFunc") == 0) { setStencilFunction(parseStencilFunc(value), _stencilFunctionRef, _stencilFunctionMask); } else if (name.compare("stencilFuncRef") == 0) { setStencilFunction(_stencilFunction, parseInt(value), _stencilFunctionMask); } else if (name.compare("stencilFuncMask") == 0) { setStencilFunction(_stencilFunction, _stencilFunctionRef, parseUInt(value)); } else if (name.compare("stencilOpSfail") == 0) { setStencilOperation(parseStencilOp(value), _stencilOpDpfail, _stencilOpDppass); } else if (name.compare("stencilOpDpfail") == 0) { setStencilOperation(_stencilOpSfail, parseStencilOp(value), _stencilOpDppass); } else if (name.compare("stencilOpDppass") == 0) { setStencilOperation(_stencilOpSfail, _stencilOpDpfail, parseStencilOp(value)); } else { CCLOG("Unsupported render state string '%s'.", name.c_str()); } }
/** \brief parse option from configuration file. * * \param[in,out] as Pointer to session handle * \param[in] opt name of option to set (left of =) * \param[in] param name of value for option (right of =) * \param type type for param, currently unused * \return 0 if parsing was successful, -1 if an error occured. currently * always returns 0 */ PRIVATE int set_option(auto_handle *as, const char *opt, const char *param, option_type type) { int32_t numval; int32_t result = SUCCESS; dbg_printf(P_INFO2, "[config] %s=%s (type: %d)", opt, param, type); assert(as != NULL); if(!strcmp(opt, "url")) { dbg_printf(P_ERROR, "the 'url' option is not supported any more, please use the 'feed' option instead!"); result = FAILURE; } else if(!strcmp(opt, "feed")) { result = parseFeed(&as->feeds, param); } else if(!strcmp(opt, "transmission-home")) { set_path(param, &as->transmission_path); } else if(!strcmp(opt, "prowl-apikey")) { as->prowl_key = am_strdup(param); } else if(!strcmp(opt, "toasty-deviceid")) { as->toasty_key = am_strdup(param); } else if(!strcmp(opt, "pushalot-token")) { as->pushalot_key = am_strdup(param); } else if(!strcmp(opt, "transmission-version")) { if (!strcmp(param, "external")) { /* we should probably only set this when transmission-external is set */ as->transmission_version = AM_TRANSMISSION_EXTERNAL; } else if(param[0] == '1' && param[1] == '.' && param[2] == '2') { as->transmission_version = AM_TRANSMISSION_1_2; } else if(param[0] == '1' && param[1] == '.' && param[2] == '3') { as->transmission_version = AM_TRANSMISSION_1_3; } else { dbg_printf(P_ERROR, "Unknown parameter: %s=%s", opt, param); } } else if (!strcmp(opt, "transmission-external")) { set_path(param, &as->transmission_external); as->transmission_version = AM_TRANSMISSION_EXTERNAL; } else if(!strcmp(opt, "torrent-folder")) { set_path(param, &as->torrent_folder); } else if(!strcmp(opt, "statefile")) { set_path(param, &as->statefile); } else if(!strcmp(opt, "rpc-host")) { as->host = am_strdup(param); } else if(!strcmp(opt, "rpc-auth")) { as->auth = am_strdup(param); } else if(!strcmp(opt, "upload-limit")) { numval = parseUInt(param); if(numval > 0) { as->upspeed = (uint16_t)numval; } else { dbg_printf(P_ERROR, "Unknown parameter: %s=%s", opt, param); } } else if(!strcmp(opt, "rpc-port")) { numval = parseUInt(param); if (numval > 1024 && numval < 65535) { as->rpc_port = numval; } else if(numval != -1) { dbg_printf(P_ERROR, "RPC port must be an integer between 1025 and 65535, reverting to default (%d)\n\t%s=%s", AM_DEFAULT_RPCPORT, opt, param); } else { dbg_printf(P_ERROR, "Unknown parameter: %s=%s", opt, param); } } else if(!strcmp(opt, "interval")) { numval = parseUInt(param); if(numval > 0) { as->check_interval = numval; } else if(numval != -1) { dbg_printf(P_ERROR, "Interval must be 1 minute or more, reverting to default (%dmin)\n\t%s=%s", AM_DEFAULT_INTERVAL, opt, param); } else { dbg_printf(P_ERROR, "Unknown parameter: %s=%s", opt, param); } } else if(!strcmp(opt, "use-transmission")) { if(!strncmp(param, "0", 1) || !strncmp(param, "no", 2)) { as->use_transmission = 0; } else if(!strncmp(param, "1", 1) || !strncmp(param, "yes", 3)) { as->use_transmission = 1; } else { dbg_printf(P_ERROR, "Unknown parameter: %s=%s", opt, param); } } else if(!strcmp(opt, "start-torrents")) { if(!strncmp(param, "0", 1) || !strncmp(param, "no", 2)) { as->start_torrent = 0; } else if(!strncmp(param, "1", 1) || !strncmp(param, "yes", 3)) { as->start_torrent = 1; } else { dbg_printf(P_ERROR, "Unknown parameter for option '%s': '%s'", opt, param); } } else if(!strcmp(opt, "patterns")) { dbg_printf(P_ERROR, "the 'patterns' option is not supported any more, please use the 'filter' option instead!"); result = FAILURE; } else if(!strcmp(opt, "filter")) { result = parseFilter(&as->filters, param); } else { dbg_printf(P_ERROR, "Unknown option: %s", opt); } return result; }
utilStatus utilCmdLine_parse( utilCmdLine self, int argc, char * argv[] ) { utilStatus status = UTIL_STATUS_NO_ERROR; utilCmdLineImpl * This = utilCmdLine_safeCast( self, &status ); if( status == UTIL_STATUS_NO_ERROR ) { int i; for( i = 1; i < argc; ++i ) { bool notFound = true; unsigned j; for( j = 0; notFound && j < This->count; ++j ) { CmdLineDef * def = This->defs + j; if( 0 == strncmp( argv[i], def->key, def->len )) { const char * value = argv[i] + def->len; notFound = false; switch( def->type ) { case CmdLineType_BOOLEAN: if( 0 == strcasecmp( value, "T" )) { def->value.t = true; } else if( 0 == strcasecmp( value, "true" )) { def->value.t = true; } else if( 0 == strcasecmp( value, "1" )) { def->value.t = true; } else if( 0 == strcasecmp( value, "F" )) { def->value.t = false; } else if( 0 == strcasecmp( value, "false" )) { def->value.t = false; } else if( 0 == strcasecmp( value, "0" )) { def->value.t = false; } else { status = UTIL_STATUS_TYPE_MISMATCH; } break; case CmdLineType_CHAR: if( strlen( value ) > 1 ) { status = UTIL_STATUS_TYPE_MISMATCH; } else { def->value.b = (byte)value[0]; } break; case CmdLineType_BYTE: def->value.b = (byte)parseInt( value, 0, 0xFF, &status ); break; case CmdLineType_SHORT: def->value.s = (short)parseInt( value, -0x8000, 0x7FFF, &status ); break; case CmdLineType_USHORT: def->value.s = (short)parseInt( value, 0, 0xFFFF, &status ); break; case CmdLineType_INT: def->value.i = parseInt( value, INT_MIN, INT_MAX, &status ); break; case CmdLineType_UINT: def->value.i = (int)parseUInt( value, &status ); break; case CmdLineType_FLOAT: def->value.f = parseFloat( value, &status ); break; case CmdLineType_DOUBLE: def->value.d = parseDouble( value, &status ); break; case CmdLineType_STRING: if( strlen( value ) >= utilCmdLine_VALUE_LEN ) { status = UTIL_STATUS_OUT_OF_RANGE; } else { strncpy( def->value.sz, value, utilCmdLine_VALUE_LEN ); def->value.sz[utilCmdLine_VALUE_LEN-1] = '\0'; } break; } } } if( notFound ) { fprintf( stderr, "Ignored argument: %s\n", argv[i] ); status = UTIL_STATUS_NOT_FOUND; } } } return status; }