Find the appropriate entry for short options
This commit is contained in:
parent
9dfca6f3c1
commit
e7d0b2c114
|
@ -4,7 +4,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
const uint8_t GARGOYLE_ERR_SUCCESS = 0;
|
const uint8_t GARGOYLE_ERR_SUCCESS = 0;
|
||||||
const uint8_t GARGOYLE_ERR_RESERVED = 1;
|
const uint8_t GARGOYLE_ERR_UNKNOWN_OPT = 1;
|
||||||
const uint8_t GARGOYLE_ERR_UNKNOWN_OPT = 2;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,5 +22,6 @@ struct gargoyle_opt {
|
||||||
#define GARGOYLE_EZ_OPT(brand) brand, (sizeof(brand) - 1), 0[brand] // >:)
|
#define GARGOYLE_EZ_OPT(brand) brand, (sizeof(brand) - 1), 0[brand] // >:)
|
||||||
|
|
||||||
struct gargoyle_opt *gargoyle_find_brand(uint16_t optc, struct gargoyle_opt *optv, const char *brand);
|
struct gargoyle_opt *gargoyle_find_brand(uint16_t optc, struct gargoyle_opt *optv, const char *brand);
|
||||||
|
struct gargoyle_opt *gargoyle_find_emblem(uint16_t optc, struct gargoyle_opt *optv, const char emblem);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,37 +2,40 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
uint8_t gargoyle_digest(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv) {
|
uint8_t gargoyle_digest(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv) {
|
||||||
uint8_t status = 1;
|
while(1) {
|
||||||
|
|
||||||
while(status) {
|
|
||||||
const char *arg = **argv;
|
const char *arg = **argv;
|
||||||
|
|
||||||
if(!arg || *arg != '-' || !*(arg + 1)) {
|
if(!arg || *arg != '-' || !*(arg + 1)) {
|
||||||
status = 0;
|
return GARGOYLE_ERR_SUCCESS;
|
||||||
break;
|
|
||||||
} else if(*arg == '-' && *(arg + 1) == '-' && !*(arg + 2)) {
|
} else if(*arg == '-' && *(arg + 1) == '-' && !*(arg + 2)) {
|
||||||
*argc -= 1;
|
*argc -= 1;
|
||||||
*argv += 1;
|
*argv += 1;
|
||||||
status = 0;
|
return GARGOYLE_ERR_SUCCESS;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gargoyle_opt *opt = NULL;
|
struct gargoyle_opt *opt = NULL;
|
||||||
|
|
||||||
if(*(arg + 1) == '-') {
|
if(*(arg + 1) == '-') {
|
||||||
opt = gargoyle_find_brand(optc, optv, arg + 2);
|
opt = gargoyle_find_brand(optc, optv, arg + 2);
|
||||||
} else {
|
|
||||||
/* loop through short opts */
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!opt) {
|
if(!opt) {
|
||||||
status = GARGOYLE_ERR_UNKNOWN_OPT;
|
return GARGOYLE_ERR_UNKNOWN_OPT;
|
||||||
break;
|
}
|
||||||
|
} else {
|
||||||
|
const char *idx = arg + 1;
|
||||||
|
|
||||||
|
for(; *idx; idx += 1) {
|
||||||
|
opt = gargoyle_find_emblem(optc, optv, *idx);
|
||||||
|
|
||||||
|
if(!opt) {
|
||||||
|
return GARGOYLE_ERR_UNKNOWN_OPT;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*argc -= 1;
|
*argc -= 1;
|
||||||
*argv += 1;
|
*argv += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return GARGOYLE_ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
10
src/sleuth.c
10
src/sleuth.c
|
@ -11,3 +11,13 @@ struct gargoyle_opt *gargoyle_find_brand(uint16_t optc, struct gargoyle_opt *opt
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct gargoyle_opt *gargoyle_find_emblem(uint16_t optc, struct gargoyle_opt *optv, const char emblem) {
|
||||||
|
for(; optc; optc -= 1, optv += 1) {
|
||||||
|
if(emblem == optv->emblem) {
|
||||||
|
return optv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue