Exemplo n.º 1
0
LWRESULT Cx_ConsoleMgr::CallBackCommand(COMMAND_LINE& command_line)	
{
	if(command_line.empty())
		return LWDP_OK;

	COMMAND_LINE::iterator lineIter = command_line.begin();
	
	if(*lineIter == "b")
		return CON::CONSOLE_BREAK;

	if(*lineIter == "q")
		return CON::CONSOLE_EXIT;

	if(*lineIter == "cls")
	{
#ifdef LWDP_PLATFORM_DEF_WIN32
		system("cls");
#else
		system("clear");
#endif
		return LWDP_OK;
	}
	
	COMMAND_MAP::iterator iter = mCommandMap.find(*lineIter);
	if(iter == mCommandMap.end())
	{
		std::cout << "Unknow Command!" << std::endl;
		return LWDP_OK;
	}

	iter->second.commandFun(command_line);
	
	return LWDP_OK;
}
Exemplo n.º 2
0
LWRESULT Cx_ConsoleMgr::PraseCommandLine(const std::string& command_str, COMMAND_LINE& command_line,
												const std::string& div_char)
{
	std::string match(div_char);
	bool removeEmpty = true;
    std::string::size_type start = 0;           // starting position for searches
    std::string::size_type skip  = 1;            // positions to skip after a match

	command_line.clear();
    skip = match.length();
    while (start != std::string::npos)
    {
        // get a complete range [start..end)
        std::string::size_type end = command_str.find_first_of(match, start);

        // null strings always match in string::find, but
        // a skip of 0 causes infinite loops. pretend that
        // no tokens were found and extract the whole string
        if (skip == 0) end = std::string::npos;

        std::string token = command_str.substr(start, end - start);

        if (!(removeEmpty && token.empty()))
        {
            // extract the token and add it to the result list
            command_line.push_back(token);
        }

        // start the next range
        if ((start = end) != std::string::npos) start += skip;
    }

	return LWDP_OK;
}
Exemplo n.º 3
0
void ecasv_parse_command_line(ECA_CONTROL_INTERFACE *eci, int argc, char *argv[])
{
    COMMAND_LINE cline = COMMAND_LINE (argc, argv);
    if (cline.size() == 0 ||
            cline.has("--version") ||
            cline.has("--help") ||
            cline.has("-h")) {
        ecasv_print_usage();
        exit(1);
    }

    ecasv_enable_debug = false;
    ecasv_enable_cumulative_mode = false;
    ecasv_rate_msec = 0;
    ecasv_buffersize = 0;

    cline.begin();
    cline.next(); // 1st argument
    while (cline.end() != true) {
        string arg = cline.current();
        if (arg.size() > 0) {
            if (arg[0] != '-') {
                if (ecasv_input == "")
                    ecasv_input = arg;
                else if (ecasv_output == "")
                    ecasv_output = arg;
            }
            else {
                string prefix = kvu_get_argument_prefix(arg);
                if (prefix == "b")
                    ecasv_buffersize = atol(kvu_get_argument_number(1, arg).c_str());
                if (prefix == "c") ecasv_enable_cumulative_mode = true;
                if (prefix == "d") ecasv_enable_debug = true;
                if (prefix == "f")
                    ecasv_format_string = string(arg.begin() + 3, arg.end());
                if (prefix == "I") ecasv_log_display_mode = false; // jkc: addition
                if (prefix == "L") ecasv_log_display_mode = true; // jkc: addition
                if (prefix == "r")
                    ecasv_rate_msec = atol(kvu_get_argument_number(1, arg).c_str());
                if (prefix == "G" ||
                        prefix == "B" ||
                        (prefix.size() > 0 && prefix[0] == 'M') ||
                        prefix == "r" ||
                        prefix == "z") {
                    eci->command("cs-option " + arg);
                }
            }
        }
        cline.next();
    }

    ecasv_fill_defaults();
}