Skip to content

File wsh_shell_str.c

FileList > src > wsh_shell_str.c

Go to the source code of this file

  • #include "wsh_shell_str.h"

Public Functions

Type Name
void WshShellStr_AccessBitsToStr (WshShell_Size_t access, WshShell_Char_t * pOutStr)
Converts access permission bits to a human-readable string like "rwx".
void WshShellStr_DecrInterCnt (WshShell_Size_t * pInterCnt)
Decrease buffer counter.
void WshShellStr_GroupBitsToStr (WshShell_Size_t group, WshShell_Size_t groupMaxNum, WshShell_Char_t * pOutStr)
Converts group bitmask into symbolic group string (e.g. "*--*", "---*", etc).
void WshShellStr_IncrInterCnt (WshShell_Size_t * pInterCnt, WshShell_Size_t buffSize)
Increase buffer counter.
WshShell_Bool_t WshShellStr_IsPrintableAscii (WshShell_Char_t ch)
Check whether the given character is a printable ASCII symbol.
void WshShellStr_ParseToArgcArgv (WshShell_Char_t * pStr, WshShell_Size_t * pArgNum, const WshShell_Char_t * pArgBuff, WshShell_Size_t maxArgNum)
Parse a string into space-separated tokens, handling quoted substrings as single tokens.
WshShell_Char_t * WshShellStr_TrimString (WshShell_Char_t * pString, WshShell_Size_t len)
Trim tabulation and spaces from beginning and end of a string.

Public Functions Documentation

function WshShellStr_AccessBitsToStr

Converts access permission bits to a human-readable string like "rwx".

1
2
3
4
void WshShellStr_AccessBitsToStr (
    WshShell_Size_t access,
    WshShell_Char_t * pOutStr
) 

This function translates access bit flags into a POSIX-style permission string. The result is written into the provided buffer.

The output format is: * 'rifWSH_SHELL_OPT_ACCESS_READis set, otherwise'-'-'w'ifWSH_SHELL_OPT_ACCESS_WRITEis set, otherwise'-'-'x'ifWSH_SHELL_OPT_ACCESS_EXECUTEis set, otherwise'-'-'A'ifaccess == WSH_SHELL_OPT_ACCESS_ANY` (optional fourth character)

Examples: * 0x00"---" * 0x03"rw-" * 0x07"rwx" * 0xFFFFFFFF"rwxA"

Parameters:

  • access Bitmask of access flags (e.g. WSH_SHELL_OPT_ACCESS_READ).
  • pOutStr Buffer to write result to. Must be at least 5 bytes long.

function WshShellStr_DecrInterCnt

Decrease buffer counter.

1
2
3
void WshShellStr_DecrInterCnt (
    WshShell_Size_t * pInterCnt
) 

Parameters:

  • pInterCnt Pointer to a counter.

function WshShellStr_GroupBitsToStr

Converts group bitmask into symbolic group string (e.g. "*--*", "---*", etc).

1
2
3
4
5
void WshShellStr_GroupBitsToStr (
    WshShell_Size_t group,
    WshShell_Size_t groupMaxNum,
    WshShell_Char_t * pOutStr
) 

Produces a fixed-length string of '*' and '-' characters from highest to lowest group index.

Example for 2 groups: * WSH_SHELL_CMD_GROUP_ADMIN = bit 0 → rightmost char * WSH_SHELL_CMD_GROUP_MANUF = bit 3 → leftmost char

Parameters:

  • group Bitmask of groups.
  • groupMaxNum Groups max number.
  • pOutStr Output buffer (must be at least WSH_SHELL_GROUP_STR_LEN).

function WshShellStr_IncrInterCnt

Increase buffer counter.

1
2
3
4
void WshShellStr_IncrInterCnt (
    WshShell_Size_t * pInterCnt,
    WshShell_Size_t buffSize
) 

Parameters:

  • pInterCnt Pointer to a counter.
  • buffSize Size of a buffer.

function WshShellStr_IsPrintableAscii

Check whether the given character is a printable ASCII symbol.

1
2
3
WshShell_Bool_t WshShellStr_IsPrintableAscii (
    WshShell_Char_t ch
) 

This function checks if the character belongs to the range of printable ASCII characters (from 0x20 ' ' to 0x7E '~').

Parameters:

  • ch Character to check.

Returns:

true if the character is printable ASCII; false otherwise.


function WshShellStr_ParseToArgcArgv

Parse a string into space-separated tokens, handling quoted substrings as single tokens.

1
2
3
4
5
6
void WshShellStr_ParseToArgcArgv (
    WshShell_Char_t * pStr,
    WshShell_Size_t * pArgNum,
    const WshShell_Char_t * pArgBuff,
    WshShell_Size_t maxArgNum
) 

This function splits the input string pStr into tokens by replacing spaces with null terminators (\0). Tokens are written as pointers to the beginning of each token into the pArgBuff array. Quoted substrings (enclosed in double quotes "), if any, are treated as a single token. Quotes themselves are removed during parsing. ч

Note:

This function modifies the input string in-place. Spaces and quotes are replaced with \0. Escaped or nested quotes are not supported.

Example: Input: "arg1 arg2 \"quoted string" arg3"</tt> Output: <tt>pArgBuff = { "arg1", "arg2", "quoted string", "arg3" }, *pArgNum = 4

Parameters:

  • pStr Pointer to the null-terminated string to be parsed. Will be modified in-place.
  • pArgNum Pointer to a counter that will be set to the number of parsed tokens.
  • pArgBuff Array of string pointers (tokens). Must be large enough to hold all tokens.
  • maxArgNum Maximum number of tokens that can be stored in pArgBuff. Excess tokens are discarded.

function WshShellStr_TrimString

Trim tabulation and spaces from beginning and end of a string.

1
2
3
4
WshShell_Char_t * WshShellStr_TrimString (
    WshShell_Char_t * pString,
    WshShell_Size_t len
) 

Parameters:

  • pString Pointer to a string to be trimmed.
  • len Length of an input string.

Returns:

WshShell_Char_t*: Pointer to a trimmed string.



The documentation for this class was generated from the following file src/wsh_shell_str.c