Fix prop listing
add prop parsing (which calls prop listing through -h or --help) add short and long opts to index by which override key (which can get ugly) WARNING API CHANGE, but only a little one - and nobody uses it yet SVN revision: 10039
This commit is contained in:
parent
b58b2da294
commit
6d01330752
|
@ -77,6 +77,8 @@ typedef struct Ecore_Config_Listener_List {
|
|||
typedef struct Ecore_Config_Prop {
|
||||
char *key;
|
||||
char *description;
|
||||
char short_opt;
|
||||
char *long_opt;
|
||||
char *ptr;
|
||||
Ecore_Config_Type type;
|
||||
long val,lo,hi,step;
|
||||
|
@ -125,7 +127,9 @@ int ecore_config_get_rgb(const char *key,int *r, int *g, int *b);
|
|||
float ecore_config_get_float(const char *key);
|
||||
char *ecore_config_get_theme(const char *key);
|
||||
char *ecore_config_get_as_string(const char *key);
|
||||
void ecore_config_describe(const char *key, char *desc);
|
||||
int ecore_config_describe(const char *key, char *desc);
|
||||
int ecore_config_set_short_opt(const char *key, char short_opt);
|
||||
int ecore_config_set_long_opt(const char *key, char *long_opt);
|
||||
int ecore_config_set(const char *key,char *val);
|
||||
int ecore_config_set_typed(const char *key,void *val,int type);
|
||||
int ecore_config_set_string(const char *key,char *val);
|
||||
|
@ -187,9 +191,14 @@ int ecore_config_save_file(char *file);
|
|||
# define ECORE_CONFIG_ERR_FAIL (-1)
|
||||
# define ECORE_CONFIG_ERR_SUCC (0)
|
||||
|
||||
# define ECORE_CONFIG_PARSE_HELP (-2)
|
||||
# define ECORE_CONFIG_PARSE_EXIT (-1)
|
||||
# define ECORE_CONFIG_PARSE_CONTINUE (0)
|
||||
|
||||
/* convenience mathods in convenience.c */
|
||||
int ecore_config_evas_font_path_apply(Evas *evas);
|
||||
void ecore_config_prop_list_describe(void);
|
||||
void ecore_config_args_display(void);
|
||||
int ecore_config_args_parse(int argc, char **argv);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ ecore_config_evas_font_path_apply (Evas * evas)
|
|||
ptr++;
|
||||
if (ptr < end)
|
||||
*ptr = '\0';
|
||||
printf("appending font %s\n", font_path_tmp);
|
||||
|
||||
evas_font_path_append (evas, font_path_tmp);
|
||||
ptr++;
|
||||
font_path_tmp = ptr;
|
||||
|
@ -38,10 +38,13 @@ printf("appending font %s\n", font_path_tmp);
|
|||
static char *_ecore_config_short_types[]={ "nil", "int", "flt", "str", "rgb", "str"};
|
||||
|
||||
void
|
||||
ecore_config_prop_list_describe(void)
|
||||
ecore_config_args_display(void)
|
||||
{
|
||||
Ecore_Config_Prop *props;
|
||||
|
||||
|
||||
printf("Application information to be added here!\n\n"); //FIXME
|
||||
printf("Supported Options:\n");
|
||||
printf(" -h, --help\t\t Print this text\n");
|
||||
if (!__ecore_config_bundle_local) return;
|
||||
props = __ecore_config_bundle_local->data;
|
||||
while (props)
|
||||
|
@ -50,8 +53,96 @@ ecore_config_prop_list_describe(void)
|
|||
props = props->next;
|
||||
continue;
|
||||
}
|
||||
printf(" --%s\t [%s] %s\n", props->key, _ecore_config_short_types[props->type], props->description);
|
||||
printf(" %c%c%c --%s\t <%s> %s\n", props->short_opt?'-':' ',
|
||||
props->short_opt?props->short_opt:' ', props->short_opt?',':' ',
|
||||
props->long_opt?props->long_opt:props->key,
|
||||
_ecore_config_short_types[props->type], props->description);
|
||||
|
||||
props = props->next;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ecore_config_parse_set(Ecore_Config_Prop *prop, char *arg) {
|
||||
if (!arg)
|
||||
printf("Missing expected attribute for option --%s\n", prop->key);
|
||||
else
|
||||
ecore_config_set(prop->key, arg);
|
||||
}
|
||||
|
||||
int
|
||||
ecore_config_args_parse(int argc, char **argv)
|
||||
{
|
||||
int nextarg, next_short_opt, found;
|
||||
char *arg;
|
||||
char *long_opt, short_opt;
|
||||
Ecore_Config_Prop *prop;
|
||||
|
||||
nextarg = 1;
|
||||
while (nextarg < argc) {
|
||||
arg = argv[nextarg];
|
||||
|
||||
if (*arg != '-') {
|
||||
printf("Unexpected attribute \"%s\"\n", arg);
|
||||
nextarg++;
|
||||
continue;
|
||||
}
|
||||
|
||||
next_short_opt = 1;
|
||||
short_opt = *(arg + next_short_opt);
|
||||
|
||||
if (short_opt == '-') {
|
||||
long_opt = arg + 2;
|
||||
|
||||
if (!strcmp(long_opt, "help")) {
|
||||
ecore_config_args_display();
|
||||
return ECORE_CONFIG_PARSE_HELP;
|
||||
}
|
||||
|
||||
found = 0;
|
||||
prop = __ecore_config_bundle_local->data;
|
||||
while (prop) {
|
||||
if ((prop->long_opt && !strcmp(long_opt, prop->long_opt))
|
||||
|| !strcmp(long_opt, prop->key)) {
|
||||
found = 1;
|
||||
ecore_config_parse_set(prop, argv[++nextarg]);
|
||||
break;
|
||||
}
|
||||
prop = prop->next;
|
||||
}
|
||||
if (!found) {
|
||||
printf("Unrecognised option \"%s\"\n\n", long_opt);
|
||||
ecore_config_args_display();
|
||||
return ECORE_CONFIG_PARSE_EXIT;
|
||||
}
|
||||
} else {
|
||||
while (short_opt) {
|
||||
if (short_opt == 'h') {
|
||||
ecore_config_args_display();
|
||||
return ECORE_CONFIG_PARSE_HELP;
|
||||
} else {
|
||||
found = 0;
|
||||
prop = __ecore_config_bundle_local->data;
|
||||
while (prop) {
|
||||
if (short_opt == prop->short_opt) {
|
||||
found = 1;
|
||||
ecore_config_parse_set(prop, argv[++nextarg]);
|
||||
break;
|
||||
}
|
||||
prop = prop->next;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
printf("Unrecognised option '%c'\n\n", short_opt);
|
||||
return ECORE_CONFIG_PARSE_EXIT;
|
||||
}
|
||||
}
|
||||
short_opt = *(arg + ++next_short_opt);
|
||||
}
|
||||
}
|
||||
nextarg++;
|
||||
}
|
||||
|
||||
return ECORE_CONFIG_PARSE_CONTINUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -301,12 +301,26 @@ static int ecore_config_add(const char *key,char *val) {
|
|||
type=ecore_config_guess_type(key, val);
|
||||
return ecore_config_add_typed(key,val,type); }
|
||||
|
||||
void ecore_config_describe(const char *key, char *desc) {
|
||||
int ecore_config_describe(const char *key, char *desc) {
|
||||
Ecore_Config_Prop *e;
|
||||
if ((e=ecore_config_get(key)))
|
||||
e->description = strdup(desc);
|
||||
}
|
||||
if (!(e=ecore_config_get(key)))
|
||||
return ECORE_CONFIG_ERR_NODATA;
|
||||
e->description = strdup(desc);
|
||||
return ECORE_CONFIG_ERR_SUCC;}
|
||||
|
||||
int ecore_config_set_short_opt(const char *key, char short_opt) {
|
||||
Ecore_Config_Prop *e;
|
||||
if (!(e=ecore_config_get(key)))
|
||||
return ECORE_CONFIG_ERR_NODATA;
|
||||
e->short_opt = short_opt;
|
||||
return ECORE_CONFIG_ERR_SUCC;}
|
||||
|
||||
int ecore_config_set_long_opt(const char *key, char *long_opt) {
|
||||
Ecore_Config_Prop *e;
|
||||
if (!(e=ecore_config_get(key)))
|
||||
return ECORE_CONFIG_ERR_NODATA;
|
||||
e->long_opt = strdup(long_opt);
|
||||
return ECORE_CONFIG_ERR_SUCC;}
|
||||
|
||||
int ecore_config_set_typed(const char *key,void *val,int type) {
|
||||
Ecore_Config_Prop *e;
|
||||
|
|
Loading…
Reference in New Issue