Ejemplo n.º 1
0
char* match_cmd(const char* text, int state)
{
  static STR_INT_MAP_ITER it;
  static int len = 0;
  const char* cmd = NULL;

  if (!state)
  {
    it = cmd_map.begin();
    len = strlen(text);
  }

  while(it != cmd_map.end())
  {
    cmd = it->first.c_str();
    it++;
    if (strncmp(cmd, text, len) == 0)
    {
      int32_t cmd_len = strlen(cmd) + 1;
      // memory will be freed by readline
      return strncpy(new char[cmd_len], cmd, cmd_len);
    }
  }
  return NULL;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
Archivo: main.cpp Proyecto: 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;
  }
}
Ejemplo n.º 4
0
//为统计MINI版所需文件,添加此文件统计。
void ResourceManager::addFileStat(const char* name, FILE_TYPE tp)
{
    //此函数已暂时完成其历史使命。
    return;
    std::map<FILE_TYPE, STR_INT_MAP*>::iterator iter = _fileStatMap->find(tp);
    STR_INT_MAP* map = NULL;
    if (iter != _fileStatMap->end())
    {
        map = iter->second;
    }
    else
    {
        map = new STR_INT_MAP();
        _fileStatMap->insert(std::pair<FILE_TYPE, STR_INT_MAP*>(tp, map));
    }
    map->insert(std::pair<std::string, int>(name, 1));
}