lib: getopt: rework and extend getopt library

Getopt has been rework in this way that calling it does not require
extra state parameter and its execution is thread safe.
Global parameters describing the state of the getopt function have been
made available to ensure full API compatibility in using this library.
However, referencing these global variables directly is not thread
safe. In order to get the state of the getopt function for the thread
that is currently using it, call: getopt_state_get();

Extended the library with getopt_long and getopt_long_only functions.

Moved getopt libary from utils to posix.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
Jakub Rzeszutko 2021-07-01 11:00:15 +02:00 committed by Carles Cufí
commit d4559f53fa
22 changed files with 978 additions and 179 deletions

View file

@ -547,7 +547,7 @@ static int exec_cmd(const struct shell *shell, size_t argc, const char **argv,
if (!ret_val) {
#if CONFIG_SHELL_GETOPT
z_shell_getopt_init(&shell->ctx->getopt_state);
getopt_init();
#endif
z_flag_cmd_ctx_set(shell, true);