lib

morphux C utility library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/lib

commit ac1a5beee65180d1aeb4b45d2a7dc98f8bd779b4
parent 767e694345429b30f99ee0add6e6d82eddd6fb54
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Wed, 18 Jan 2017 18:30:41 +0100

Add(Args): Now support multiple single args in one '-'

Diffstat:
Msrc/m_args.c | 33++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/m_args.c b/src/m_args.c @@ -65,24 +65,27 @@ u32_t read_opt(const int ac, char **av, const margs_t *args) { p_version(); /* Search the option in the args array */ - for (it = 0; args[it].opt != 0 && args[it].opt != av[i][1]; it++) - ; + for (u32_t z = 1; av[i][z] != '\0'; z++) { + for (it = 0; args[it].opt != 0 && args[it].opt != av[i][z]; it++) + ; - /* Can't find the option */ - if (args[it].opt == 0) { - m_error("Unknow option -%s\n", &(av[i][1])); - opt_help(args); - } else { - if (args[it].take_arg) { - if (i + 1 < (u32_t)ac) { - args[it].callback(av[++i]); + /* Can't find the option */ + if (args[it].opt == 0) { + m_error("Unknow option -%s\n", &(av[i][z])); + opt_help(args); + } else { + if (args[it].take_arg) { + if (i + 1 < (u32_t)ac) { + args[it].callback(av[++i]); + break ; + } else { + m_error("Option -%c must take an argument\n", + args[it].opt); + opt_help(args); + } } else { - m_error("Option -%c must take an argument\n", - args[it].opt); - opt_help(args); + args[it].callback(NULL); } - } else { - args[it].callback(NULL); } }