diff --git a/ketopt.h b/ketopt.h index 70193a5..8ae1811 100644 --- a/ketopt.h +++ b/ketopt.h @@ -73,13 +73,17 @@ static int ketopt(ketopt_t *s, int argc, char *argv[], int permute, const char * } s->opt = 0, opt = '?', s->pos = -1; if (longopts) { /* parse long options */ - int k, n_matches = 0; - const ko_longopt_t *o = 0; + int k, n_exact = 0, n_partial = 0; + const ko_longopt_t *o = 0, *o_exact = 0, *o_partial = 0; for (j = 2; argv[s->i][j] != '\0' && argv[s->i][j] != '='; ++j) {} /* find the end of the option name */ for (k = 0; longopts[k].name != 0; ++k) - if (strncmp(&argv[s->i][2], longopts[k].name, j - 2) == 0) - ++n_matches, o = &longopts[k]; - if (n_matches == 1) { + if (strncmp(&argv[s->i][2], longopts[k].name, j - 2) == 0) { + if (longopts[k].name[j - 2] == 0) ++n_exact, o_exact = &longopts[k]; + else ++n_partial, o_partial = &longopts[k]; + } + if (n_exact > 1 || (n_exact == 0 && n_partial > 1)) return '?'; + o = n_exact == 1? o_exact : n_partial == 1? o_partial : 0; + if (o) { s->opt = opt = o->val, s->longidx = o - longopts; if (argv[s->i][j] == '=') s->arg = &argv[s->i][j + 1]; if (o->has_arg == 1 && argv[s->i][j] == '\0') { diff --git a/main.c b/main.c index fac05b1..34c4696 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ #include "mmpriv.h" #include "ketopt.h" -#define MM_VERSION "2.15-r915-dirty" +#define MM_VERSION "2.15-r917-dirty" #ifdef __linux__ #include