CLIHANDLER *CCLITerminal::FindCommandHandler(CLISESSION *pSession, int &nDepts, char *pszNode) { CLIHANDLER *pHandler; if (m_pCLIService->GetRunLevel() == RUNLEVEL_DEBUG) pHandler = FindCommand(pSession, m_CliDebugCommandHandlers, nDepts, pszNode); else pHandler = FindCommand(pSession, m_pCommandHandlers, nDepts, pszNode); return pHandler; }
Command* CommandMap::AddCommand(Command command) { if (FindCommand(command.Name) || FindCommand(command.ShortName)) return nullptr; this->Commands.push_back(command); return &this->Commands.back(); }
void CConsole::Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp) { CCommand *pCommand = FindCommand(pName, Flags); bool DoAdd = false; if(pCommand == 0) { pCommand = new(mem_alloc(sizeof(CCommand), sizeof(void*))) CCommand; DoAdd = true; } pCommand->m_pfnCallback = pfnFunc; pCommand->m_pUserData = pUser; pCommand->m_pName = pName; GenerateUsage(pParams, pCommand->m_pUsage); pCommand->m_pHelp = pHelp; pCommand->m_pParams = pParams; pCommand->m_Flags = Flags; pCommand->m_Temp = false; if(pCommand->m_Flags&CFGFLAG_USER) pCommand->SetAccessLevel(ACCESS_LEVEL_USER); if(DoAdd) AddCommandSorted(pCommand); }
void CPlayerWatcherBase::SendReject(TUid aInterfaceUid, TUint aTransactionId) { TRemConClientId clientId; (void)FindCommand(aInterfaceUid, aTransactionId, clientId); ReceiveReject(clientId); }
T_void CompileCommand(T_byte8 *p_line) { T_byte8 command[80] ; T_byte8 command2[80] ; T_byte8 *p_open ; T_sword16 commandNum ; sscanf(p_line, "%s", command) ; p_open = strstr(command, "(") ; if (p_open) *p_open = '\0' ; command2[0] = '\0' ; sscanf(command, "%s", command2) ; if (!command2[0]) return ; commandNum = FindCommand(command2) ; if (commandNum == -1) { printf("Error! Unknown command '%s' on line %d\n", command2, G_line) ; exit(201) ; } // printf("command: <%s> = %d\n", command2, commandNum) ; OutputByte((T_byte8)commandNum) ; p_open = strstr(p_line, "(") ; if (!p_open) { printf("Error! Missing '(' on line %d\n", G_line) ; exit(202); } CompileArgs(p_open, G_commands[commandNum].numArgs) ; }
//----------------------------------------------------------------------------- // return values: 0 - OK, 1 - wrong arguments, 2 - wrong command, 3 - string too long, 4 -- unclosed string int mglParser::ParseDat(mglGraph *gr, std::wstring str, mglData &res) { std::wstring arg[32]; str = mgl_trim_ws(str); long n,k=0; for(k=0;k<32;k++) // parse string to substrings (by spaces) { n = mglFindArg(str); if(n<1) { if(n<0) str=str.substr(0,-n); break; } arg[k] = str.substr(0,n);// k++; str = str.substr(n+1); str = mgl_trim_ws(str); } // try to find last argument if(!str.empty()) { arg[k] = str; k++; } if(k<1) n = 0; else { // fill arguments by its values mglArg *a = new mglArg[k+1]; FillArg(gr, k, arg, a+1); a[0].type=0; a[0].d=&res; // alocate new arrays and execute the command itself int i; std::string kk; const char *id="dsn"; for(i=0;i<k;i++) { kk += id[a[i].type]; a[i].s.assign(a[i].w.begin(),a[i].w.end()); } const mglCommand *rts=FindCommand(arg[0].c_str()); if(!rts || rts->type!=4) n = 2; else n = rts->exec(gr, k, a, kk.c_str(), 0); delete []a; } return n; }
//----------------------------------------------------------------------------- // return values : 0 -- OK, 1 -- wrong arguments, 2 -- wrong command, 3 -- unclosed string int mglParser::Exec(mglGraph *gr, const wchar_t *com, long n, mglArg *a, const std::wstring &var, const wchar_t *opt) { int i; const char *id="dsn"; std::string k; for(i=0;i<n;i++) { k += id[a[i].type]; size_t len = wcstombs(NULL,a[i].w.c_str(),0)+1; char *buf = new char[len]; memset(buf,0,len); wcstombs(buf,a[i].w.c_str(),len); a[i].s = buf; delete []buf; } const mglCommand *rts=FindCommand(com); if(!rts || rts->type==6) return 2; /* if(rts->type == 4) { if(n<1 || CheckForName(var)) return 2; a[0].type = 0; a[0].d = AddVar(var.c_str()); a[0].w = var; k[0] = 'd'; }*/ char *o=0; if(opt && *opt) // TODO: parse arguments of options { long len = mgl_wcslen(opt); o = new char[len+1]; for(i=0;i<len+1;i++) o[i]=opt[i]; } int res=rts->exec(gr, n, a, k.c_str(), o); if(o) delete []o; return res; }
void PrintHelp( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); if( 1 == cmd.argCount() ) { sLog.Log( cmdName, "Available commands:" ); for( size_t i = 0; i < EVETOOL_COMMAND_COUNT; ++i ) { const EVEToolCommand* c = &EVETOOL_COMMANDS[i]; sLog.Log( cmdName, "%s", c->name ); } sLog.Log( cmdName, "You can get detailed help by typing '%s <command> [<command>] ...'.", cmdName ); } else { for( size_t i = 1; i < cmd.argCount(); ++i ) { const std::string& cmdStr = cmd.arg( i ); const EVEToolCommand* c = FindCommand( cmdStr ); if( NULL == c ) sLog.Error( cmdName, "Unknown command '%s'.", cmdStr.c_str() ); else sLog.Log( cmdName, "%s: %s", c->name, c->description ); } } }
// use custom accelerator table to change the keyboard shortcuts displayed on said hMenu void UpdateMenuKeys(HMENU hMenu) { ATLASSERT(hMenu); int nItems = ::GetMenuItemCount(hMenu); CMenuItemInfo mi; mi.fMask = MIIM_ID | MIIM_SUBMENU; TCHAR buf[512]; CString name; for(int i = 0; i < nItems; i++) { // i hope we're not going to have GPFs like in RepairMenu! ::GetMenuItemInfo(hMenu, i, TRUE, &mi); // by position if(mi.hSubMenu) UpdateMenuKeys(mi.hSubMenu); else if(mi.wID != 0 ) { // separators etc excluded // see if there's accelerator info in text ATLASSERT(!(buf[0] = 0)); ::GetMenuString(hMenu, i, buf, sizeof(buf)/sizeof(buf[0]), MF_BYPOSITION); ATLASSERT(buf[0]); int len = lstrlen(buf), k = len; /*while(k--) if(_T('\t') == buf[k]) break; BOOL bTab = k > 0; BOOL bChanged = 1;*/ // is there any accelerator for this command nowadays? CString MenuString = FindCommand(mi.wID); MenuString = _T('\t')+MenuString; MenuString = buf+MenuString; //if(-1 == idx) { // if(bTab) // buf[k] = 0; // remove old one // else // bChanged = 0; //} //else { // if(!bTab) { // k = len; // buf[k] = _T('\t'); // } // k++; // name = dummy.NameFromAccel(m_pAccelTable[idx]); // ATLASSERT(k+name.GetLength() < sizeof(buf)/sizeof(buf[0])); // lstrcpy(buf+k, name); //} //if(bChanged) { // ATLASSERT(lstrlen(buf)); ::ModifyMenu(hMenu, i, MF_BYPOSITION, mi.wID, MenuString.GetBuffer(512)); MenuString.ReleaseBuffer(); // $TSEK no need to update item enable/icon states? (see wtl's command bar atlctrlw.h line 2630) //} } } }
VariableSetReturnValue CommandMap::SetVariable(const std::string& name, std::string& value, std::string& previousValue) { auto command = FindCommand(name); if (!command) return eVariableSetReturnValueError; return SetVariable(command, value, previousValue); }
void ICommand::RegisterCommand(std::string strName, ICommand* pCommand) { if(FindCommand(strName)==NULL) { gCommands[strName] = pCommand; } }
main() { initilize(); while(1) { int id; // Read line from user, and get the function id from it GetLine(); id = FindCommand(); switch(id) { case 0: mkdir(pathname); break; case 1: rmdir(pathname); break; case 2: cd(pathname); break; case 3: ls(); break; case 4: pwd(); break; case 5: creat(pathname); break; case 6: rm(pathname); break; case 7: save(); break; case 8: reload(); break; case 9: menu(); break; case 10: quit(); break; default: printf("Command not recognized! Please try again.\n\n"); break; } } return 0; }
bool CommandMap::GetVariableInt64(const std::string& name, unsigned long long& value) { auto command = FindCommand(name); if (!command || command->Type != eCommandTypeVariableInt64) return false; value = command->ValueInt64; return true; }
bool CommandMap::GetVariableString(const std::string& name, std::string& value) { auto command = FindCommand(name); if (!command || command->Type != eCommandTypeVariableString) return false; value = command->ValueString; return true; }
void ProcessCommand( const Seperator& cmd ) { const char* cmdName = cmd.arg( 0 ).c_str(); const EVEToolCommand* c = FindCommand( cmdName ); if( NULL == c ) sLog.Error( "input", "Unknown command '%s'.", cmdName ); else ( *c->callback )( cmd ); }
TInt CPlayerWatcherBase::SendRemConResponse(TUid aInterfaceUid, TUint aTransactionId, RBuf8& aData) { LOG_FUNC; TRemConClientId clientId; CInternalCommand& command = FindCommand(aInterfaceUid, aTransactionId, clientId); ReceiveUpdate(command, clientId, aData); return KErrNone; }
bool CModule::AddCommand(const CModCommand& Command) { if (Command.GetFunction() == NULL) return false; if (Command.GetCommand().find(' ') != CString::npos) return false; if (FindCommand(Command.GetCommand()) != NULL) return false; m_mCommands[Command.GetCommand()] = Command; return true; }
bool CModule::HandleCommand(const CString& sLine) { const CString& sCmd = sLine.Token(0); const CModCommand* pCmd = FindCommand(sCmd); if (pCmd) { pCmd->Call(this, sLine); return true; } OnUnknownModCommand(sLine); return false; }
void ChatTriggers::OnSourceModGameInitialized() { m_pSayCmd = FindCommand("say"); m_pSayTeamCmd = FindCommand("say_team"); if (m_pSayCmd) { SH_ADD_HOOK(ConCommand, Dispatch, m_pSayCmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Pre), false); SH_ADD_HOOK(ConCommand, Dispatch, m_pSayCmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Post), true); } if (m_pSayTeamCmd) { SH_ADD_HOOK(ConCommand, Dispatch, m_pSayTeamCmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Pre), false); SH_ADD_HOOK(ConCommand, Dispatch, m_pSayTeamCmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Post), true); } #if SOURCE_ENGINE == SE_EPISODEONE m_bIsINS = (strcmp(g_SourceMod.GetGameFolderName(), "insurgency") == 0); if (m_bIsINS) { m_pSay2Cmd = FindCommand("say2"); if (m_pSay2Cmd) { SH_ADD_HOOK(ConCommand, Dispatch, m_pSay2Cmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Pre), false); SH_ADD_HOOK(ConCommand, Dispatch, m_pSay2Cmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Post), true); } } #elif SOURCE_ENGINE == SE_NUCLEARDAWN m_pSaySquadCmd = FindCommand("say_squad"); if (m_pSaySquadCmd) { SH_ADD_HOOK(ConCommand, Dispatch, m_pSaySquadCmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Pre), false); SH_ADD_HOOK(ConCommand, Dispatch, m_pSaySquadCmd, SH_MEMBER(this, &ChatTriggers::OnSayCommand_Post), true); } #endif }
LRESULT OnExecuteCommand( HWND hWnd, WPARAM wParam, LPARAM lParam, LPCLASSDATA lpcd ) { LPFUNC lpfnFunction; /* * Find the command. */ if (( lpfnFunction = FindCommand( wParam )) != NULL ) /* * Execute it. */ ( lpfnFunction )( lpcd ); return 0; }
void NextMapManager::OnSourceModAllInitialized_Post() { #if SOURCE_ENGINE >= SE_ORANGEBOX SH_ADD_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false); #else SH_ADD_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false); #endif ConCommand *pCmd = FindCommand("changelevel"); if (pCmd != NULL) { SH_ADD_HOOK(ConCommand, Dispatch, pCmd, SH_STATIC(CmdChangeLevelCallback), false); changeLevelCmd = pCmd; } }
bool CConsole::LineIsValid(const char *pStr) { if(!pStr || *pStr == 0) return false; do { CResult Result; const char *pEnd = pStr; const char *pNextPart = 0; int InString = 0; while(*pEnd) { if(*pEnd == '"') InString ^= 1; else if(*pEnd == '\\') // escape sequences { if(pEnd[1] == '"') pEnd++; } else if(!InString) { if(*pEnd == ';') // command separator { pNextPart = pEnd+1; break; } else if(*pEnd == '#') // comment, no need to do anything more break; } pEnd++; } if(ParseStart(&Result, pStr, (pEnd-pStr) + 1) != 0) return false; CCommand *pCommand = FindCommand(Result.m_pCommand, m_FlagMask); if(!pCommand || ParseArgs(&Result, pCommand->m_pParams)) return false; pStr = pNextPart; } while(pStr && *pStr); return true; }
const Command* j1Console::CreateCommand(const char* name, j1Module* listener, uchar min_args, uchar max_args) { const Command* ret = nullptr; if(name != nullptr && strlen(name) < COMMAND_NAME_SIZE && FindCommand(name) == NULL && FindCVar(name) == nullptr) { Command com; strcpy_tolower(com.name, name); com.listener = listener; com.min_arguments = min_args; com.max_arguments = max_args; commands.PushBack(com); ret = &commands[commands.Count() - 1]; } return ret; }
bool CommandMap::ExecuteCommandWithStatus(std::string command) { int numArgs = 0; auto args = CommandLineToArgvA((PCHAR)command.c_str(), &numArgs); if (numArgs <= 0) return false; auto cmd = FindCommand(args[0]); if (!cmd) return false; std::vector<std::string> argsVect; if (numArgs > 1) for (int i = 1; i < numArgs; i++) argsVect.push_back(args[i]); if (cmd->Type == eCommandTypeCommand) { cmd->UpdateEvent(argsVect, std::string()); // if it's a command call it and return return true; } std::string previousValue; auto updateRet = SetVariable(cmd, (numArgs > 1 ? argsVect[0] : ""), previousValue); if (updateRet != eVariableSetReturnValueSuccess) return false; if (numArgs <= 1) return true; if (!cmd->UpdateEvent) return true; // no update event, so we'll just return with what we set the value to auto ret = cmd->UpdateEvent(argsVect, std::string()); if (ret) // error, revert the variable return true; // error, revert the variable this->SetVariable(cmd, previousValue, std::string()); return false; }
const CVar* j1Console::CreateCVar(const char* name, bool value, j1Module* listener, bool read_only, bool serialize) { CVar* ret = nullptr; if(name != nullptr && strlen(name) < COMMAND_NAME_SIZE && FindCommand(name) == nullptr && FindCVar(name) == nullptr) { CVar var; strcpy_tolower(var.name, name); var.listener = listener; var.read_only = read_only; var.serialize = serialize; var.value.b = value; var.type = CVar::is_bool; cvars.PushBack(var); ret = &cvars[cvars.Count() - 1]; } return ret; }
void Run(CommandSource &source, const std::vector<Flux::string> ¶ms) { int c=0; if(!params.empty()) { Command *com = FindCommand(params[1], C_PRIVATE); if(com && !com->OnHelp(source, "")) source.Reply(L"No help available for \2%s\2", params[1].c_str()); else if(!com) source.Reply("No help available for \2%s\2", params[1].c_str()); Log(source.u) << "used help command on " << params[1]; } else { for(auto val : Commandsmap) { source.Reply("\2%-16s\2 %s", val.second->name.c_str(), val.second->GetDesc().c_str()); ++c; } source.Reply("Total of \2%i\2 commands", c); Log(source.u) << "used help command"; } }
const CVar* j1Console::CreateCVar(const char* name, const char* string, j1Module* listener, bool read_only, bool serialize) { CVar* ret = nullptr; if(name != nullptr && strlen(name) < COMMAND_NAME_SIZE && FindCommand(name) == nullptr && FindCVar(name) == nullptr) { CVar var; strcpy_tolower(var.name, name); var.listener = listener; var.read_only = read_only; var.serialize = serialize; var.type = CVar::is_string; cvars.PushBack(var); ret = &cvars[cvars.Count() - 1]; int len = strlen(string); ret->value.s = new char[len+1]; strcpy_s(ret->value.s, len + 1, string); } return ret; }
void Run(CommandSource &source, const std::vector<Flux::string> ¶ms) { Flux::string cmds; if(!params.empty()) { Command *c = FindCommand(params[1], C_CHANNEL); if(c && !c->OnHelp(source, "")) source.Reply("No help available for \2%s\2", params[1].c_str()); else if(!c) source.Reply("No help available for \2%s\2", params[1].c_str()); Log(source.u) << "used help command on " << params[1]; } else { for(auto val : ChanCommandMap) //As you can see C++11 is MUCH better than C++98 cmds += val.second->name+" "; cmds.trim(); cmds.tolower(); source.u->SendMessage("Local %s Commands:", source.c->name.c_str()); source.u->SendMessage(cmds); Log(source.u) << "used help command"; } }
void CConsole::Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp) { CCommand *pCommand = FindCommand(pName, Flags); bool DoAdd = false; if(pCommand == 0) { pCommand = new(mem_alloc(sizeof(CCommand), sizeof(void*))) CCommand; DoAdd = true; } pCommand->m_pfnCallback = pfnFunc; pCommand->m_pUserData = pUser; pCommand->m_pName = pName; pCommand->m_pHelp = pHelp; pCommand->m_pParams = pParams; pCommand->m_Flags = Flags; pCommand->m_Temp = false; if(DoAdd) AddCommandSorted(pCommand); }
//***************************************************************************** // This is the main routine of the command line processor, this routine should // ideally run in the while loop in the main(), but it also can be run in // a task/thread on a RTOS // // This function checks if enter key has been detected by the interrupt // service routine and if it's true, the processing of the buffer and // execution of the command will take place // //***************************************************************************** void CMDLineScheduler (void) { uart_info_t *packet = GetUartPointer(); uart_cmd_t *cmd = GetCmdPointer(); timing_info_t *timing = GetTimerPointer(); stack_info_t *stack = GetStackPointer(); if(packet->enterFlag) { CalculateUsage(timing); timing->cmdStart = SysTickValueGet(); cmd->currentCmd = UARTEncodeCommand(packet); UARTGetArguments(packet, cmd); if (!FindCommand(cmd)) { if (packet->rxCount >= MIN_CMD_LENGTH) { UARTprintf(CMD_NOT_FOUND); } } else { ExecuteCommand(cmd); SaveToStack(cmd); if (stack->execFromStack) { ExecuteFromStack(); } } CMDResetCtrlStructure(cmd); UARTResetCtrlStructure(packet); timing->cmdStop = SysTickValueGet(); // display different input prompts based on mode // during scripting, show current stack position if (stack->saveCommands) { UARTprintf(STACK_PROMPT, stack->stackIdx); } else { UARTprintf(INPUT_PROMPT); } } }