diff options
Diffstat (limited to 'indra/newview/llcommandlineparser.cpp')
-rw-r--r-- | indra/newview/llcommandlineparser.cpp | 121 |
1 files changed, 76 insertions, 45 deletions
diff --git a/indra/newview/llcommandlineparser.cpp b/indra/newview/llcommandlineparser.cpp index c7359a8865..f31ff14df6 100644 --- a/indra/newview/llcommandlineparser.cpp +++ b/indra/newview/llcommandlineparser.cpp @@ -2,30 +2,25 @@ * @file llcommandlineparser.cpp * @brief The LLCommandLineParser class definitions * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -58,7 +53,7 @@ namespace po = boost::program_options; -// *NTOE:MEP - Currently the boost object reside in file scope. +// *NOTE:MEP - Currently the boost object reside in file scope. // This has a couple of negatives, they are always around and // there can be only one instance of each. // The plus is that the boost-ly-ness of this implementation is @@ -161,6 +156,12 @@ public: return mIsComposing; } + // Needed for boost 1.42 + virtual bool is_required() const + { + return false; // All our command line options are optional. + } + virtual bool apply_default(boost::any& value_store) const { return false; // No defaults. @@ -174,7 +175,6 @@ public: { mNotifyCallback(*value); } - } protected: @@ -218,20 +218,20 @@ protected: //---------------------------------------------------------------------------- // LLCommandLineParser defintions //---------------------------------------------------------------------------- -void LLCommandLineParser::addOptionDesc(const LLString& option_name, +void LLCommandLineParser::addOptionDesc(const std::string& option_name, boost::function1<void, const token_vector_t&> notify_callback, unsigned int token_count, - const LLString& description, - const LLString& short_name, + const std::string& description, + const std::string& short_name, bool composing, bool positional, bool last_option) { // Compose the name for boost::po. // It takes the format "long_name, short name" - const LLString comma(","); - LLString boost_option_name = option_name; - if(short_name != LLString::null) + const std::string comma(","); + std::string boost_option_name = option_name; + if(short_name != LLStringUtil::null) { boost_option_name += comma; boost_option_name += short_name; @@ -261,7 +261,7 @@ void LLCommandLineParser::addOptionDesc(const LLString& option_name, } } -bool parseAndStoreResults(po::command_line_parser& clp) +bool LLCommandLineParser::parseAndStoreResults(po::command_line_parser& clp) { try { @@ -273,26 +273,37 @@ bool parseAndStoreResults(po::command_line_parser& clp) // when we have options that are a prefix of other options (aka, --help and --helperuri). clp.style((po::command_line_style::default_style & ~po::command_line_style::allow_guessing) | po::command_line_style::allow_long_disguise); + if(mExtraParser) + { + clp.extra_parser(mExtraParser); + } + po::basic_parsed_options<char> opts = clp.run(); po::store(opts, gVariableMap); } catch(po::error& e) { llwarns << "Caught Error:" << e.what() << llendl; + mErrorMsg = e.what(); return false; } catch(LLCLPError& e) { llwarns << "Caught Error:" << e.what() << llendl; + mErrorMsg = e.what(); return false; } catch(LLCLPLastOption&) { - // Continue without parsing. - llwarns << "Found tokens past last option. Ignoring." << llendl; + // This exception means a token was read after an option + // that must be the last option was reached (see url and slurl options) - // boost::po will have stored a mal-formed option. + // boost::po will have stored a malformed option. // All such options will be removed below. + // The last option read, the last_option option, and its value + // are put into the error message. + std::string last_option; + std::string last_value; for(po::variables_map::iterator i = gVariableMap.begin(); i != gVariableMap.end();) { po::variables_map::iterator tempI = i++; @@ -300,7 +311,27 @@ bool parseAndStoreResults(po::command_line_parser& clp) { gVariableMap.erase(tempI); } + else + { + last_option = tempI->first; + LLCommandLineParser::token_vector_t* tv = + boost::any_cast<LLCommandLineParser::token_vector_t>(&(tempI->second.value())); + if(!tv->empty()) + { + last_value = (*tv)[tv->size()-1]; + } + } } + + // Continue without parsing. + std::ostringstream msg; + msg << "Caught Error: Found options after last option: " + << last_option << " " + << last_value; + + llwarns << msg.str() << llendl; + mErrorMsg = msg.str(); + return false; } return true; } @@ -386,14 +417,9 @@ const LLCommandLineParser::token_vector_t& LLCommandLineParser::getOption(const // LLControlGroupCLP defintions //---------------------------------------------------------------------------- void setControlValueCB(const LLCommandLineParser::token_vector_t& value, - const LLString& opt_name, + const std::string& opt_name, LLControlGroup* ctrlGroup) { - if(value.size() > 1) - { - llwarns << "Ignoring extra tokens mapped to the setting: " << opt_name << "." << llendl; - } - // *FIX: Do sematic conversion here. // LLSD (ImplString) Is no good for doing string to type conversion for... // booleans @@ -415,7 +441,7 @@ void setControlValueCB(const LLCommandLineParser::token_vector_t& value, { // There's a token. check the string for true/false/1/0 etc. BOOL result = false; - BOOL gotSet = LLString::convertToBOOL(value[0], result); + BOOL gotSet = LLStringUtil::convertToBOOL(value[0], result); if(gotSet) { ctrl->setValue(LLSD(result), false); @@ -430,7 +456,7 @@ void setControlValueCB(const LLCommandLineParser::token_vector_t& value, default: { // For the default types, let llsd do the conversion. - if(value.size() > 1) + if(value.size() > 1 && ctrl->isType(TYPE_LLSD)) { // Assume its an array... LLSD llsdArray; @@ -445,6 +471,11 @@ void setControlValueCB(const LLCommandLineParser::token_vector_t& value, } else if(value.size() > 0) { + if(value.size() > 1) + { + llwarns << "Ignoring extra tokens mapped to the setting: " << opt_name << "." << llendl; + } + LLSD llsdValue; llsdValue.assign(LLSD::String(value[0])); ctrl->setValue(llsdValue, false); @@ -462,14 +493,14 @@ void setControlValueCB(const LLCommandLineParser::token_vector_t& value, } } -void LLControlGroupCLP::configure(const LLString& config_filename, LLControlGroup* controlGroup) +void LLControlGroupCLP::configure(const std::string& config_filename, LLControlGroup* controlGroup) { // This method reads the llsd based config file, and uses it to set // members of a control group. LLSD clpConfigLLSD; llifstream input_stream; - input_stream.open(config_filename.c_str(), std::ios::in | std::ios::binary); + input_stream.open(config_filename, std::ios::in | std::ios::binary); if(input_stream.is_open()) { @@ -481,13 +512,13 @@ void LLControlGroupCLP::configure(const LLString& config_filename, LLControlGrou LLSD::String long_name = option_itr->first; LLSD option_params = option_itr->second; - LLString desc("n/a"); + std::string desc("n/a"); if(option_params.has("desc")) { desc = option_params["desc"].asString(); } - LLString short_name = LLString::null; + std::string short_name = LLStringUtil::null; if(option_params.has("short")) { short_name = option_params["short"].asString(); @@ -520,7 +551,7 @@ void LLControlGroupCLP::configure(const LLString& config_filename, LLControlGrou boost::function1<void, const token_vector_t&> callback; if(option_params.has("map-to") && (NULL != controlGroup)) { - LLString controlName = option_params["map-to"].asString(); + std::string controlName = option_params["map-to"].asString(); callback = boost::bind(setControlValueCB, _1, controlName, controlGroup); } |