liboptcfg
diff src/optcfg.c @ 1:8fd2858c6a29
example (test) program
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 14 Nov 2015 14:12:30 +0200 |
parents | 10b89befcaa9 |
children | 9c73004c7af3 |
line diff
1.1 --- a/src/optcfg.c Fri Nov 13 23:48:31 2015 +0200 1.2 +++ b/src/optcfg.c Sat Nov 14 14:12:30 2015 +0200 1.3 @@ -258,21 +258,26 @@ 1.4 1.5 static int get_opt(struct optcfg *oc, const char *arg) 1.6 { 1.7 - int i; 1.8 + int i, ndashes = 0; 1.9 1.10 - if(arg[0] != '-' || !arg[1]) { 1.11 - return -1; 1.12 + while(*arg && *arg == '-') { 1.13 + ndashes++; 1.14 + arg++; 1.15 } 1.16 1.17 - if(arg[2]) { /* match long options */ 1.18 + if(ndashes > 2) { 1.19 + arg -= ndashes; 1.20 + } 1.21 + 1.22 + if(arg[1]) { /* match long options */ 1.23 for(i=0; oc->optlist[i].opt != -1; i++) { 1.24 - if(strcmp(arg + 1, oc->optlist[i].s) == 0) { 1.25 + if(strcmp(arg, oc->optlist[i].s) == 0) { 1.26 return i; 1.27 } 1.28 } 1.29 } else { 1.30 for(i=0; oc->optlist[i].opt != -1; i++) { 1.31 - if(arg[1] == oc->optlist[i].c) { 1.32 + if(arg[0] == oc->optlist[i].c) { 1.33 return i; 1.34 } 1.35 }