static VOID SysNameHandler(LPSTR pszSysName) { __CMD_PARA_OBJ* pCmdObj = NULL; pCmdObj = FormParameterObj(pszSysName); if(NULL == pCmdObj) { PrintLine("Not enough system resource to interpret the command."); goto __TERMINAL; } if((0 == pCmdObj->byParameterNum) || (0 == pCmdObj->Parameter[0][0])) { PrintLine("Invalid command parameter."); goto __TERMINAL; } if(StrLen(pCmdObj->Parameter[0]) >= MAX_HOSTNAME_LEN) { PrintLine("System name must not exceed 16 bytes."); goto __TERMINAL; } SaveSysName(pCmdObj->Parameter[0]); StrCpy(pCmdObj->Parameter[0],&HostName[0]); __TERMINAL: if(NULL != pCmdObj) { ReleaseParameterObj(pCmdObj); } return; }
// //The following routine processes the input command string. // static DWORD CommandParser(LPCSTR lpszCmdLine) { DWORD dwRetVal = SHELL_CMD_PARSER_INVALID; DWORD dwIndex = 0; __CMD_PARA_OBJ* lpCmdParamObj = NULL; if((NULL == lpszCmdLine) || (0 == lpszCmdLine[0])) //Parameter check { return SHELL_CMD_PARSER_INVALID; } lpCmdParamObj = FormParameterObj(lpszCmdLine); if(NULL == lpCmdParamObj) //Can not form a valid command parameter object. { return SHELL_CMD_PARSER_FAILED; } //if(0 == lpCmdParamObj->byParameterNum) //There is not any parameter. //{ // return SHELL_CMD_PARSER_FAILED; //} //CD_PrintString(lpCmdParamObj->Parameter[0],TRUE); // //The following code looks up the command map,to find the correct handler that handle //the current command.Calls the corresponding command handler if found,otherwise SYS_DIAG_CMD_PARSER_INVALID //will be returned to indicate this case. // while(TRUE) { if(NULL == SysDiagCmdMap[dwIndex].lpszCommand) { dwRetVal = SHELL_CMD_PARSER_INVALID; break; } if(StrCmp(SysDiagCmdMap[dwIndex].lpszCommand,lpCmdParamObj->Parameter[0])) //Find the handler. { dwRetVal = SysDiagCmdMap[dwIndex].CommandHandler(lpCmdParamObj); break; } else { dwIndex ++; } } //Release parameter object. if(NULL != lpCmdParamObj) { ReleaseParameterObj(lpCmdParamObj); } return dwRetVal; }
// //The following routine processes the input command string. // static DWORD CommandParser(LPCSTR lpszCmdLine) { DWORD dwRetVal = SHELL_CMD_PARSER_INVALID; DWORD dwIndex = 0; __CMD_PARA_OBJ* lpCmdParamObj = NULL; if((NULL == lpszCmdLine) || (0 == lpszCmdLine[0])) //Parameter check { return SHELL_CMD_PARSER_INVALID; } lpCmdParamObj = FormParameterObj(lpszCmdLine); if(NULL == lpCmdParamObj) //Can not form a valid command parameter object. { return SHELL_CMD_PARSER_FAILED; } if(0 == lpCmdParamObj->byParameterNum) //There is not any parameter. { return SHELL_CMD_PARSER_FAILED; } // //The following code looks up the command map,to find the correct handler that handle //the current command.If find,then calls the handler,else,return SYS_DIAG_CMD_PARSER_INVALID //to indicate the failure. // while(TRUE) { if(NULL == SysDiagCmdMap[dwIndex].lpszCommand) { dwRetVal = SHELL_CMD_PARSER_INVALID; break; } if(StrCmp(SysDiagCmdMap[dwIndex].lpszCommand,lpCmdParamObj->Parameter[0])) //Find the handler. { dwRetVal = SysDiagCmdMap[dwIndex].CommandHandler(lpCmdParamObj); break; } else { dwIndex ++; } } //__TERMINAL: if(NULL != lpCmdParamObj) { ReleaseParameterObj(lpCmdParamObj); } return dwRetVal; }
static DWORD CommandParser(LPCSTR lpszCmdLine) { __CMD_PARA_OBJ* lpParamObj = NULL; DWORD dwRetVal = SHELL_CMD_PARSER_INVALID; DWORD dwIndex = 0; BOOL bValidCmd = FALSE; lpParamObj = FormParameterObj(lpszCmdLine); if(NULL == lpParamObj) //Can not create parameter object. { return SHELL_CMD_PARSER_FAILED; } if(0 != lpParamObj->byParameterNum) //Valid parameter(s) exits. { while(IOCtrlCmdMap[dwIndex].lpszCommand) { if(StrCmp(IOCtrlCmdMap[dwIndex].lpszCommand, lpParamObj->Parameter[0])) { bValidCmd = TRUE; //Find the valid command. break; } dwIndex ++; } if(bValidCmd) //Handle the command. { dwRetVal = IOCtrlCmdMap[dwIndex].CommandRoutine(lpParamObj); } else { dwRetVal = SHELL_CMD_PARSER_INVALID; } } ReleaseParameterObj(lpParamObj); //Release the parameter object. return dwRetVal; }
//Command analyzing routine,it analyzes user's input and search //command array to find a proper handler,then call it. //Default handler will be called if no proper command handler is //located. static DWORD CommandParser(LPSTR pCmdBuf) { __KERNEL_THREAD_OBJECT* hKernelThread = NULL; __CMD_PARA_OBJ* lpCmdParamObj = NULL; DWORD dwResult = SHELL_CMD_PARSER_INVALID; //If find the correct command object,then DWORD dwIndex = 0; //Used for 'for' loop. lpCmdParamObj = FormParameterObj(pCmdBuf); if(NULL == lpCmdParamObj || lpCmdParamObj->byParameterNum < 1) //Can not form a valid command parameter object. { CD_PrintString(pCmdBuf,TRUE); goto __END; } dwIndex = 0; //is bat file? if(strstr(lpCmdParamObj->Parameter[0],"./")) { BatHandler(lpCmdParamObj); dwResult = SHELL_CMD_PARSER_SUCCESS; goto __END; } while(CmdObj[dwIndex].CmdStr) { if(StrCmp(CmdObj[dwIndex].CmdStr,lpCmdParamObj->Parameter[0])) { CmdObj[dwIndex].CmdHandler(lpCmdParamObj); //Call the command handler. dwResult = SHELL_CMD_PARSER_SUCCESS; break; } dwIndex ++; } if(dwResult == SHELL_CMD_PARSER_SUCCESS) { goto __END; } dwIndex = 0; //Now,should search external command array. while(ExtCmdArray[dwIndex].lpszCmdName) { if(StrCmp(ExtCmdArray[dwIndex].lpszCmdName,lpCmdParamObj->Parameter[0])) //Found. { hKernelThread = KernelThreadManager.CreateKernelThread( (__COMMON_OBJECT*)&KernelThreadManager, 0, KERNEL_THREAD_STATUS_READY, PRIORITY_LEVEL_NORMAL, ExtCmdArray[dwIndex].ExtCmdHandler, (LPVOID)lpCmdParamObj, //? NULL, NULL); if(!ExtCmdArray[dwIndex].bBackground) //Should wait. { DeviceInputManager.SetFocusThread((__COMMON_OBJECT*)&DeviceInputManager, (__COMMON_OBJECT*)hKernelThread); //Give the current input focus to this thread. hKernelThread->WaitForThisObject((__COMMON_OBJECT*)hKernelThread); DeviceInputManager.SetFocusThread((__COMMON_OBJECT*)&DeviceInputManager,NULL); KernelThreadManager.DestroyKernelThread( (__COMMON_OBJECT*)&KernelThreadManager, (__COMMON_OBJECT*)hKernelThread); //Destroy it. //Set focus thread to shell. } dwResult = SHELL_CMD_PARSER_SUCCESS; goto __END; } dwIndex ++; } //DefaultHandler(NULL); //Call the default command handler. __END: ReleaseParameterObj(lpCmdParamObj); return dwResult; }
DWORD IoCtrlStart(LPVOID p) { DWORD dwCurrentPtr = 0; __KERNEL_THREAD_MESSAGE Msg; BYTE bt; WORD wr = 0x0700; DWORD dwMapIndex = 0; BOOL bValidCmd = FALSE; __CMD_PARA_OBJ* lpParamObj = NULL; DWORD dwRetVal = 0; PrintPound(); //Print out the prompt of this application. while(TRUE) { if(KernelThreadManager.GetMessage((__COMMON_OBJECT*)KernelThreadManager.lpCurrentKernelThread,&Msg)) { if(MSG_KEY_DOWN == Msg.wCommand) //This is a key down event. { bt = (BYTE)Msg.dwParam; if(VK_RETURN == bt) //The ENTER key is pressed. { strCmdBuffer[dwCurrentPtr] = 0; //Set the end flag. dwCurrentPtr = 0; //Set the pointer to begin. // //The following code handles the command. // lpParamObj = FormParameterObj(&strCmdBuffer[0]); if(NULL == lpParamObj) //Can not create parameter object. { PrintLine("Fatal error occurs,application exit."); goto __TERMINAL; //Exit the application. } if(0 != lpParamObj->byParameterNum) //Valid parameter(s) exits. { while(IOCtrlCmdMap[dwMapIndex].lpszCommand) { if(StrCmp(IOCtrlCmdMap[dwMapIndex].lpszCommand, lpParamObj->Parameter[0])) { bValidCmd = TRUE; //Find the valid command. break; } dwMapIndex ++; } if(bValidCmd) //Handle the command. { dwRetVal = IOCtrlCmdMap[dwMapIndex].CommandRoutine(lpParamObj); } else { PrintLine("Unrecognized command."); } } bValidCmd = FALSE; dwMapIndex = 0; ReleaseParameterObj(lpParamObj); //Release the parameter object. if(IOCTRL_TERMINAL == dwRetVal) goto __TERMINAL; PrintPound(); } else if(VK_BACKSPACE == bt) //Delete one character. { if(dwCurrentPtr) { dwCurrentPtr --; GotoPrev(); //Erase one character from screen. } } else //This only a normal key down event. { if(dwCurrentPtr < MAX_BUFFER_LEN) //If the buffer is not overflow. { strCmdBuffer[dwCurrentPtr] = bt; dwCurrentPtr ++; wr += bt; PrintCh(wr); //Print the character to screen. wr = 0x0700; //Restore the chatacter's display //attribute. } } } } } __TERMINAL: return 0; }