Generic parser¶
Overview¶
The generic parser is a simple parser for parsing mount options,filesystem options, driver options, subsystem options, etc.
Parser API¶
- intmatch_token(char*s,constmatch_table_ttable,substring_targs[])¶
Find a token (and optional args) in a string
Parameters
char*sthe string to examine for token/argument pairs
constmatch_table_ttablematch_table_t describing the set of allowed option tokens and thearguments that may be associated with them. Must be terminated with a
structmatch_tokenwhose pattern is set to the NULL pointer.substring_targs[]array of
MAX_OPT_ARGSsubstring_telements. Used to return matchlocations.
Description
Detects which if any of a set of token strings has been passedto it. Tokens can include up toMAX_OPT_ARGS instances of basic c-styleformat identifiers which will be taken into account when matching thetokens, and whose locations will be returned in theargs array.
- intmatch_int(substring_t*s,int*result)¶
scan a decimal representation of an integer from a substring_t
Parameters
substring_t*ssubstring_t to be scanned
int*resultresulting integer on success
Description
Attempts to parse thesubstring_ts as a decimal integer.
Return
On success, setsresult to the integer represented by the stringand returns 0. Returns -EINVAL or -ERANGE on failure.
- intmatch_uint(substring_t*s,unsignedint*result)¶
scan a decimal representation of an integer from a substring_t
Parameters
substring_t*ssubstring_t to be scanned
unsignedint*resultresulting integer on success
Description
Attempts to parse thesubstring_ts as a decimal integer.
Return
On success, setsresult to the integer represented by the stringand returns 0. Returns -EINVAL or -ERANGE on failure.
- intmatch_u64(substring_t*s,u64*result)¶
scan a decimal representation of a u64 from a substring_t
Parameters
substring_t*ssubstring_t to be scanned
u64*resultresulting unsigned long long on success
Description
Attempts to parse thesubstring_ts as a long decimalinteger.
Return
On success, setsresult to the integer represented by the stringand returns 0. Returns -EINVAL or -ERANGE on failure.
- intmatch_octal(substring_t*s,int*result)¶
scan an octal representation of an integer from a substring_t
Parameters
substring_t*ssubstring_t to be scanned
int*resultresulting integer on success
Description
Attempts to parse thesubstring_ts as an octal integer.
Return
On success, setsresult to the integer represented by the stringand returns 0. Returns -EINVAL or -ERANGE on failure.
- intmatch_hex(substring_t*s,int*result)¶
scan a hex representation of an integer from a substring_t
Parameters
substring_t*ssubstring_t to be scanned
int*resultresulting integer on success
Description
Attempts to parse thesubstring_ts as a hexadecimal integer.
Return
On success, setsresult to the integer represented by the stringand returns 0. Returns -EINVAL or -ERANGE on failure.
- boolmatch_wildcard(constchar*pattern,constchar*str)¶
parse if a string matches given wildcard pattern
Parameters
constchar*patternwildcard pattern
constchar*strthe string to be parsed
Description
Parse the stringstr to check if matches wildcardpatternpattern. The pattern may contain two types of wildcards:
‘*’ - matches zero or more characters
‘?’ - matches one character
Return
If thestr matches thepattern, return true, else return false.
- size_tmatch_strlcpy(char*dest,constsubstring_t*src,size_tsize)¶
Copy the characters from a substring_t to a sized buffer
Parameters
char*destwhere to copy to
constsubstring_t*srcsubstring_tto copysize_tsizesize of destination buffer
Description
Copy the characters insubstring_tsrc to thec-style stringdest. Copy no more thansize - 1 characters, plusthe terminating NUL.
Return
length ofsrc.
- char*match_strdup(constsubstring_t*s)¶
allocate a new string with the contents of a substring_t
Parameters
constsubstring_t*ssubstring_tto copy
Description
Allocates and returns a string filled with the contents ofthesubstring_ts. The caller is responsible for freeing the returnedstring withkfree().
Return
the address of the newly allocated NUL-terminated string orNULL on error.