Parse: return sections in real order

This commit is contained in:
Philippe Pepiot 2010-04-15 01:57:35 +02:00
parent 7f7bbd1f09
commit 18b702c112
3 changed files with 41 additions and 37 deletions

View File

@ -404,10 +404,10 @@ conf_layout_section(void)
{
if(conf.layout_system && conf.nlayout > 1)
{
menu_new_item(&menulayout.item[conf.nlayout-i-1], fetch_opt_first(layout[i], "", "symbol").str,
menu_new_item(&menulayout.item[i], fetch_opt_first(layout[i], "", "symbol").str,
uicb_set_layout, p);
menulayout.item[conf.nlayout-i-1].check = name_to_func("check_layout", func_list);
menulayout.item[i].check = name_to_func("check_layout", func_list);
}
conf.layout[i].symbol = fetch_opt_first(layout[i], "TILE (default)", "symbol").str;
@ -477,7 +477,7 @@ conf_tag_section(void)
for(i = 0; i < sc; ++i)
tags[i] = emalloc(n + 2, sizeof(Tag));
for(i = (n - 1); i >= 0; i--)
for(i = 0; i < n; i++)
{
j = fetch_opt_first(tag[i], "-1", "screen").num;
@ -554,7 +554,7 @@ void
conf_menu_section(void)
{
char *tmp2;
int i, j, aj;
int i, j;
struct conf_sec *menu, **set_menu, **item;
menu = fetch_section_first(NULL, "menu");
@ -596,12 +596,11 @@ conf_menu_section(void)
conf.menu[i].item = emalloc(conf.menu[i].nitem, sizeof(MenuItem));
for(j = 0; j < conf.menu[i].nitem; ++j)
{
aj = (conf.menu[i].nitem - 1) - j;
conf.menu[i].item[aj].name = fetch_opt_first(item[j], "item_wname", "name").str;
conf.menu[i].item[aj].func = name_to_func(fetch_opt_first(item[j], "", "func").str, func_list);
conf.menu[i].item[aj].cmd = fetch_opt_first(item[j], "", "cmd").str;
conf.menu[i].item[aj].check = name_to_func(fetch_opt_first(item[j], "", "check").str, func_list);
conf.menu[i].item[aj].submenu = fetch_opt_first(item[j], "", "submenu").str;
conf.menu[i].item[j].name = fetch_opt_first(item[j], "item_wname", "name").str;
conf.menu[i].item[j].func = name_to_func(fetch_opt_first(item[j], "", "func").str, func_list);
conf.menu[i].item[j].cmd = fetch_opt_first(item[j], "", "cmd").str;
conf.menu[i].item[j].check = name_to_func(fetch_opt_first(item[j], "", "check").str, func_list);
conf.menu[i].item[j].submenu = fetch_opt_first(item[j], "", "submenu").str;
}
}
free(item);
@ -639,7 +638,7 @@ conf_launcher_section(void)
void
conf_keybind_section(void)
{
int i, j, aj;
int i, j;
struct conf_sec *sec, **ks;
struct opt_type *opt;
@ -651,25 +650,24 @@ conf_keybind_section(void)
for(i = 0; i < conf.nkeybind; ++i)
{
aj = conf.nkeybind - i - 1;
opt = fetch_opt(ks[i], "", "mod");
for(j = 0; j < fetch_opt_count(opt); ++j)
keys[aj].mod |= char_to_modkey(opt[j].str, key_list);
keys[i].mod |= char_to_modkey(opt[j].str, key_list);
free(opt);
keys[aj].keysym = XStringToKeysym(fetch_opt_first(ks[i], "None", "key").str);
keys[i].keysym = XStringToKeysym(fetch_opt_first(ks[i], "None", "key").str);
keys[aj].func = name_to_func(fetch_opt_first(ks[i], "", "func").str, func_list);
keys[i].func = name_to_func(fetch_opt_first(ks[i], "", "func").str, func_list);
if(keys[aj].func == NULL)
if(keys[i].func == NULL)
{
warnx("configuration : Unknown Function \"%s\".", fetch_opt_first(ks[i], "", "func").str);
keys[aj].func = uicb_spawn;
keys[i].func = uicb_spawn;
}
keys[aj].cmd = fetch_opt_first(ks[i], "", "cmd").str;
keys[i].cmd = fetch_opt_first(ks[i], "", "cmd").str;
}
free(ks);

View File

@ -78,7 +78,7 @@ static char * get_kw_name(enum conf_type);
static TAILQ_HEAD(, conf_keyword) keywords;
static TAILQ_HEAD(, conf_stack) stack;
static SLIST_HEAD(, conf_sec) config;
static TAILQ_HEAD(, conf_sec) config;
static struct conf_keyword *curk; /* current keyword */
static struct conf_stack *curw; /* current word */
static const struct opt_type opt_type_null = { 0, 0, False, NULL };
@ -255,13 +255,13 @@ get_conf(const char *name)
curk = TAILQ_FIRST(&keywords);
curw = TAILQ_FIRST(&stack);
SLIST_INIT(&config);
TAILQ_INIT(&config);
while (!TAILQ_EMPTY(&keywords)) {
switch (curk->type) {
case SEC_START:
s = get_section();
SLIST_INSERT_HEAD(&config, s, entry);
TAILQ_INSERT_TAIL(&config, s, entry);
break;
default:
errx(1, "%s:%d: near '%s', config out of any section",
@ -281,6 +281,9 @@ get_section(void)
s = emalloc(1, sizeof(*s));
s->name = strdup(curw->name);
TAILQ_INIT(&s->sub);
SLIST_INIT(&s->optlist);
pop_stack();
pop_keyword();
@ -298,7 +301,7 @@ get_section(void)
break;
case SEC_START:
sub = get_section();
SLIST_INSERT_HEAD(&s->sub, sub, entry);
TAILQ_INSERT_TAIL(&s->sub, sub, entry);
s->nsub++;
case SEC_END:
break;
@ -403,7 +406,7 @@ print_unused(struct conf_sec *sec)
if (!sec)
{
SLIST_FOREACH(s, &config, entry)
TAILQ_FOREACH(s, &config, entry)
print_unused(s);
return;
}
@ -413,8 +416,8 @@ print_unused(struct conf_sec *sec)
warnx("%s:%d, unused param %s",
file.name, o->line, o->name);
SLIST_FOREACH(s, &sec->sub, entry)
if (!SLIST_EMPTY(&s->sub))
TAILQ_FOREACH(s, &sec->sub, entry)
if (!TAILQ_EMPTY(&s->sub))
print_unused(s);
}
@ -427,7 +430,7 @@ free_conf(struct conf_sec *sec)
if (!sec)
{
SLIST_FOREACH(s, &config, entry)
TAILQ_FOREACH(s, &config, entry)
{
free(s->name);
free_conf(s);
@ -448,10 +451,10 @@ free_conf(struct conf_sec *sec)
free(o);
}
while (!SLIST_EMPTY(&sec->sub))
while (!TAILQ_EMPTY(&sec->sub))
{
s = SLIST_FIRST(&sec->sub);
SLIST_REMOVE_HEAD(&sec->sub, entry);
s = TAILQ_FIRST(&sec->sub);
TAILQ_REMOVE(&sec->sub, s, entry);
free_conf(s);
}
@ -469,7 +472,7 @@ fetch_section(struct conf_sec *s, char *name)
if (!s) {
ret = emalloc(2, sizeof(struct conf_sec *));
SLIST_FOREACH(sec, &config, entry)
TAILQ_FOREACH(sec, &config, entry)
if (!strcmp(sec->name, name)) {
ret[0] = sec;
ret[1] = NULL;
@ -478,7 +481,7 @@ fetch_section(struct conf_sec *s, char *name)
}
else {
ret = emalloc(s->nsub+1, sizeof(struct conf_sec *));
SLIST_FOREACH(sec, &s->sub, entry) {
TAILQ_FOREACH(sec, &s->sub, entry) {
if (!strcmp(sec->name, name) && i < s->nsub)
ret[i++] = sec;
}
@ -496,11 +499,11 @@ fetch_section_first(struct conf_sec *s, char *name)
return NULL;
if (!s)
SLIST_FOREACH(sec, &config, entry)
TAILQ_FOREACH(sec, &config, entry)
if (!strcmp(sec->name, name))
return sec;
SLIST_FOREACH(sec, &s->sub, entry)
TAILQ_FOREACH(sec, &s->sub, entry)
if (!strcmp(sec->name, name))
return sec;

View File

@ -31,10 +31,10 @@ struct conf_opt {
struct conf_sec {
char *name;
SLIST_HEAD(, conf_opt) optlist;
SLIST_HEAD(, conf_sec) sub;
TAILQ_HEAD(, conf_sec) sub;
size_t nopt;
size_t nsub;
SLIST_ENTRY(conf_sec) entry;
TAILQ_ENTRY(conf_sec) entry;
};
struct opt_type {
@ -68,13 +68,14 @@ void free_conf(struct conf_sec *s);
* section.
* If section == NULL, return subsections from root section.
* Return a NULL terminated array.
* Subsections are returned in order as they are in config file
* WARNING : This MUST be free() after use.
*/
struct conf_sec **fetch_section(struct conf_sec *, char *);
/*
* Get first (last in config file) subsection matching the given name
* on the given section.
* Get first subsection matching the given name
* on the given section. (first found on the file)
*/
struct conf_sec *fetch_section_first(struct conf_sec *, char *);
@ -89,6 +90,8 @@ size_t fetch_section_count(struct conf_sec **);
* given default param.
* WARNING: This MUST be free() after use.
* WARNING: The string member is directly taken from the config struct.
* WARNING: Returned in reverse order as they are in config file.
* (I think the last option MUST overwrite all others)
*/
struct opt_type fetch_opt_first(struct conf_sec *, char *, char *);