File wsh_shell_cmd.c
FileList > src > wsh_shell_cmd.c
Go to the source code of this file
#include "wsh_shell_cmd.h"
Public Functions
| Type | Name |
|---|---|
| WSH_SHELL_RET_STATE_t | WshShellCmd_Attach (WshShellCmd_Table_t * pShellCommands, const WshShellCmd_t * pcCmdTable, WshShell_Size_t cmdNum) Initializes the command table. |
| void | WshShellCmd_DeAttach (WshShellCmd_Table_t * pShellCommands) Frees or resets the command table. |
| const WshShellCmd_t * | WshShellCmd_GetCmdByIndex (WshShellCmd_Table_t * pShellCommands, WshShell_Size_t idx) Retrieves a command by index. |
| WshShell_Size_t | WshShellCmd_GetCmdNum (WshShellCmd_Table_t * pShellCommands) Returns the number of registered commands. |
| WSH_SHELL_RET_STATE_t | WshShellCmd_GetOptValue (WshShellOption_Ctx_t * pOptCtx, WshShell_Size_t argc, const WshShell_Char_t * pArgv, WshShell_Size_t valueSize, void * pValue) Retrieves the value associated with a parsed command option. |
| WshShellOption_Ctx_t | WshShellCmd_ParseOpt (const WshShellCmd_t * pcCmd, WshShell_Size_t argc, const WshShell_Char_t * pArgv, WshShell_Size_t rights, WshShell_Size_t * pTokenPos) Parses a command-line option for a given shell command. |
| void | WshShellCmd_PrintOptionsOverview (const WshShellCmd_t * pcCmd) Prints detailed information about a shell command and its options. |
| const WshShellCmd_t * | WshShellCmd_SearchCmd (WshShellCmd_Table_t * pShellCommands, const WshShell_Char_t * pcCmdName) Finds a command by its name. |
Public Static Functions
| Type | Name |
|---|---|
| const WshShellOption_t * | WshShellCmd_FindOpt (const WshShellCmd_t * pcCmd, const WshShell_Char_t * pcStr, WshShell_Size_t strLen) |
Public Functions Documentation
function WshShellCmd_Attach
Initializes the command table.
Parameters:
pShellCommandsPointer to the shell command table.pcCmdTablePointer to the static list of commands.cmdNumNumber of commands in the list.
Returns:
WSH_SHELL_RET_STATE_SUCCESS on success.
function WshShellCmd_DeAttach
Frees or resets the command table.
Parameters:
pShellCommandsPointer to the command table.
function WshShellCmd_GetCmdByIndex
Retrieves a command by index.
Parameters:
pShellCommandsPointer to the command table.idxCommand index.
Returns:
Pointer to the command descriptor or NULL if out-of-bounds.
function WshShellCmd_GetCmdNum
Returns the number of registered commands.
Parameters:
pShellCommandsPointer to the command table.
Returns:
Number of commands.
function WshShellCmd_GetOptValue
Retrieves the value associated with a parsed command option.
This function extracts the value of a command-line option parsed by WshShellCmd_ParseOpt(), based on its type. Supported types include:
* WSH_SHELL_OPTION_STR → copied to pValue as a string
* WSH_SHELL_OPTION_INT → parsed as integer and written to pValue
* WSH_SHELL_OPTION_FLOAT→ parsed as float and written to pValue
The function expects the option to be followed by its value in pArgv. All other option types return WSH_SHELL_RET_STATE_ERR_EMPTY.
Parameters:
pOptCtxPointer to parsed option descriptor.argcArgument count.pArgvArgument vector (array of strings).valueSizeMaximum size of the output buffer (used for strings).pValueOutput buffer for value (string/int/float based on type).
Returns:
WSH_SHELL_RET_STATE_SUCCESS if value was successfully retrieved,
Returns:
WSH_SHELL_RET_STATE_ERR_PARAM if input parameters are invalid,
Returns:
WSH_SHELL_RET_STATE_ERR_EMPTY if the option doesn't accept a value,
Returns:
WSH_SHELL_RET_STATE_ERR_OVERFLOW if argument list is too short.
function WshShellCmd_ParseOpt
Parses a command-line option for a given shell command.
This function analyzes the current token in the argument list and attempts to identify a valid option defined in the given command's option table. If a valid option is found, its descriptor is returned. The token position (*pTokenPos) is advanced accordingly depending on the number of arguments that the option consumes.
If only the command name is present (i.e., argc == 1), the function checks for an option of type WSH_SHELL_OPTION_NO (indicating the command may be executed without any parameters).
Parameters:
pcCmdPointer to the shell command definition.argcNumber of arguments in the input array.pArgvArray of argument strings.pArgvUser rights bitmask for access check.pTokenPosPointer to the current token position inpArgv. Will be updated to point past the parsed option.
Returns:
A filled option descriptor if a matching option is found, or an empty descriptor if not.
function WshShellCmd_PrintOptionsOverview
Prints detailed information about a shell command and its options.
This function outputs the help text and a formatted table describing each available option for the specified command. For each option, the following fields are printed: * Short name * Long name * Option type (e.g., INT, STR, FLOAT) * Access flags (read/write/etc.) * Description/help string
Options of type WSH_SHELL_OPTION_NO and WSH_SHELL_OPTION_WAITS_INPUT are skipped.
This is typically used for displaying help information when a user requests --help for a specific command.
Parameters:
pcCmdPointer to the command descriptor whose options should be printed.
function WshShellCmd_SearchCmd
Finds a command by its name.
Parameters:
pShellCommandsPointer to the command table.pcCmdNameCommand name string.
Returns:
Pointer to the matching command descriptor or NULL if not found.
Public Static Functions Documentation
function WshShellCmd_FindOpt
The documentation for this class was generated from the following file src/wsh_shell_cmd.c