Exemplo n.º 1
0
//get the command
int parse_cmd(char* key, VSTRING & param)
{
  int cmd = CMD_NOP;
  char* token;
  //remove the space
  while (*key == ' ')
    key++;
  token = key + strlen(key);
  while (*(token - 1) == ' ' || *(token - 1) == '\n' || *(token - 1) == '\r')
    token--;
  *token = '\0';
  if (key[0] == '\0')
  {
    return cmd;
  }

#ifdef _WITH_READ_LINE
  // not blank line, add to history
  add_history(key);
#endif

  token = strchr(key, ' ');
  if (token != NULL)
  {
    *token = '\0';
  }
  //find the command
  STR_INT_MAP_ITER it = cmd_map.find(Func::str_to_lower(key));
  if (it == cmd_map.end())
  {
    return CMD_UNKNOWN;
  }
  else
  {
    cmd = it->second;
  }
  if (token != NULL)
  {
    token++;
    key = token;
  }
  else
  {
    key = NULL;
  }
  //get the parameters
  param.clear();
  while ((token = strsep(&key, " ")) != NULL)
  {
    if (token[0] == '\0')
    {
      continue;
    }
    param.push_back(token);
  }
  return cmd;
}
Exemplo n.º 2
0
Arquivo: main.cpp Projeto: alimy/tfs
int get_cmd(char* key, int32_t& cmd, bool& has_value)
{
  STR_INT_MAP_ITER it = g_sub_cmd_map.find(Func::str_to_lower(key));

  if (it == g_sub_cmd_map.end())
  {
    return CMD_UNKNOWN;
  }
  else
  {
    cmd = it->second.cmd_;
    has_value = it->second.has_value_;
    return TFS_SUCCESS;
  }
}