Conf: *TEST* make parser faster.

This commit is contained in:
Martin Duquesnoy 2009-11-06 19:52:26 +01:00
parent 1b16cb9229
commit c37e192b4d
6 changed files with 85 additions and 12 deletions

View File

@ -113,11 +113,17 @@ mouse_section(MouseBinding mb[], char *src, int ns)
for(i = 0; i < ns; ++i)
{
tmp = get_nsec(src, "mouse", i);
set_current_sauv(tmp);
mb[i].tag = get_opt(tmp, "-1", "tag").num;
mb[i].screen = get_opt(tmp, "-1", "screen").num;
mb[i].button = char_to_button(get_opt(tmp, "1", "button").str, mouse_button_list);
mb[i].func = name_to_func(get_opt(tmp, "", "func").str, func_list);
mb[i].cmd = get_opt(tmp, "", "cmd").str;
set_current_sauv(src);
}
return;
@ -128,6 +134,8 @@ conf_misc_section(char *src)
{
int pad = 12;
set_current_sauv(src);
conf.font = get_opt(src, "sans-9", "font").str;
conf.raisefocus = get_opt(src, "false", "raisefocus").bool;
conf.raiseswitch = get_opt(src, "false", "raiseswitch").bool;
@ -149,6 +157,8 @@ conf_misc_section(char *src)
void
conf_bar_section(char *src)
{
set_current_sauv(src);
conf.border.bar = get_opt(src, "false", "border").bool;
conf.bars.height = get_opt(src, "-1", "height").num;
conf.colors.bar = getcolor(get_opt(src, "#000000", "bg").str);
@ -166,6 +176,8 @@ conf_bar_section(char *src)
void
conf_root_section(char *src)
{
set_current_sauv(src);
conf.root.background_command = get_opt(src, "", "background_command").str;
if((conf.root.nmouse = get_size_sec(src, "mouse")))
@ -185,6 +197,8 @@ conf_client_section(char *src)
opt_type *buf;
/* Client misc */
set_current_sauv(src);
conf.client.borderheight = (get_opt(src, "1", "border_height").num) ? get_opt(src, "1", "border_height").num : 1;
conf.client.border_shadow = get_opt(src, "false", "border_shadow").bool;
conf.client.place_at_mouse = get_opt(src, "false", "place_at_mouse").bool;
@ -203,6 +217,8 @@ conf_client_section(char *src)
/* Titlebar part {{ */
tmp = get_sec(src, "titlebar");
set_current_sauv(tmp);
conf.titlebar.height = get_opt(tmp, "0", "height").num;
conf.titlebar.fg_normal = get_opt(tmp, "#ffffff", "fg_normal").str;
conf.titlebar.fg_focus = get_opt(tmp, "#000000", "fg_focus").str;
@ -234,6 +250,8 @@ conf_client_section(char *src)
{
tmp2 = get_nsec(tmp, "button", i);
set_current_sauv(tmp2);
/* Multi mouse section */
if((conf.titlebar.button[i].nmouse = get_size_sec(tmp2, "mouse")))
{
@ -257,6 +275,8 @@ conf_client_section(char *src)
conf.titlebar.button[i].linecoord[j].y2 = buf[3].num;
}
}
set_current_sauv(tmp);
}
}
/* }} */
@ -277,6 +297,8 @@ conf_layout_section(char *src)
conf.layout[i].func = NULL;
}
set_current_sauv(src);
conf.border.layout = get_opt(src, "false", "border").bool;
conf.colors.layout_fg = get_opt(src, "#ffffff", "fg").str;
conf.colors.layout_bg = getcolor((get_opt(src, "#000000", "bg").str));
@ -312,6 +334,8 @@ conf_layout_section(char *src)
{
tmp = get_nsec(src, "layout", i);
set_current_sauv(tmp);
if(!name_to_func((p = get_opt(tmp, "tile", "type").str), layout_list))
warnx("configuration : Unknown Layout type : \"%s\".", p);
else
@ -323,6 +347,8 @@ conf_layout_section(char *src)
conf.layout[i].symbol = get_opt(tmp, "TILE (default)", "symbol").str;
conf.layout[i].func = name_to_func(p, layout_list);
}
set_current_sauv(src);
}
}
@ -343,6 +369,8 @@ conf_tag_section(char *src)
0.50, 1, False, False, IB_Top,
layout_name_to_struct(conf.layout, "tile_right", conf.nlayout, layout_list) };
set_current_sauv(src);
conf.tag_round = get_opt(src, "false", "tag_round").bool;
conf.colors.tagselfg = get_opt(src, "#ffffff", "sel_fg").str;
conf.colors.tagselbg = getcolor(get_opt(src, "#000000", "sel_bg").str);
@ -366,6 +394,8 @@ conf_tag_section(char *src)
{
/* printf("%d -> %s\n", i, (cfgtmp = get_nsec(src, "tag", i)));*/
cfgtmp = get_nsec(src, "tag", i);
set_current_sauv(cfgtmp);
j = get_opt(cfgtmp, "-1", "screen").num;
if(j < 0 || j > sc - 1)
@ -408,6 +438,7 @@ conf_tag_section(char *src)
}
l = 0;
set_current_sauv(src);
}
for(i = 0; i < sc; ++i)
@ -427,6 +458,8 @@ conf_menu_section(char *src)
char *tmp, *tmp2;
int i, j;
set_current_sauv(src);
CHECK((conf.nmenu = get_size_sec(src, "set_menu")));
conf.menu = calloc(conf.nmenu, sizeof(Menu));
@ -434,6 +467,7 @@ conf_menu_section(char *src)
for(i = 0; i < conf.nmenu; ++i)
{
tmp = get_nsec(src, "set_menu", i);
set_current_sauv(tmp);
conf.menu[i].name = get_opt(tmp, "menu_wname", "name").str;
@ -454,12 +488,17 @@ conf_menu_section(char *src)
for(j = 0; j < get_size_sec(tmp, "item"); ++j)
{
tmp2 = get_nsec(tmp, "item", j);
set_current_sauv(tmp2);
conf.menu[i].item[j].name = get_opt(tmp2, "item_wname", "name").str;
conf.menu[i].item[j].func = name_to_func(get_opt(tmp2, "", "func").str, func_list);
conf.menu[i].item[j].cmd = (!get_opt(tmp2, "", "cmd").str) ? NULL : get_opt(tmp2, "", "cmd").str;
set_current_sauv(tmp);
}
}
set_current_sauv(src);
}
return;
@ -471,6 +510,8 @@ conf_launcher_section(char *src)
int i;
char *tmp;
set_current_sauv(src);
CHECK((conf.nlauncher = get_size_sec(src, "set_launcher")));
conf.launcher = emalloc(conf.nlauncher, sizeof(Launcher));
@ -478,10 +519,13 @@ conf_launcher_section(char *src)
for(i = 0; i < conf.nlauncher; ++i)
{
tmp = get_nsec(src, "set_launcher", i);
set_current_sauv(tmp);
conf.launcher[i].name = get_opt(tmp, "launcher", "name").str;
conf.launcher[i].prompt = get_opt(tmp, "Exec:", "prompt").str;
conf.launcher[i].command = get_opt(tmp, "exec", "command").str;
set_current_sauv(src);
}
return;
@ -494,18 +538,24 @@ conf_keybind_section(char *src)
char *tmp;
opt_type *buf;
set_current_sauv(src);
conf.nkeybind = get_size_sec(src, "key");
keys = emalloc(conf.nkeybind, sizeof(Key));
for(i = 0; i < conf.nkeybind; ++i)
{
tmp = get_nsec(src, "key", i);
set_current_sauv(tmp);
buf = get_list_opt(tmp, "", "mod", &n);
for(j = 0; j < n; ++j)
keys[i].mod |= char_to_modkey(buf[j].str, key_list);
keys[i].keysym = XStringToKeysym(get_opt(tmp, "None", "key").str);
keys[i].func = name_to_func(get_opt(tmp, "", "func").str, func_list);
if(keys[i].func == NULL)
@ -515,6 +565,8 @@ conf_keybind_section(char *src)
}
keys[i].cmd = (!get_opt(tmp, "", "cmd").str) ? NULL : get_opt(tmp, "", "cmd").str;
set_current_sauv(src);
}
return;

View File

@ -148,7 +148,7 @@ get_nsec(char *src, char *name, int n)
char *ret, *buf, **sec;
char *buf2;
if(!src)
if(!src || !strlen(src))
return NULL;
if(!name)
@ -159,8 +159,8 @@ get_nsec(char *src, char *name, int n)
sec = secname(name);
buf = erase_delim_content(src);
buf2 = erase_sec_content(buf);
buf = _strdup(sauv_delimc);
buf2 = _strdup(sauv_secc);
for(i = 0; i < n && (buf = strstr(buf, sec[SecStart])); ++i, buf += strlen(sec[SecStart]));
@ -182,7 +182,7 @@ get_size_sec(char *src, char *name)
sec = secname(name);
buf = erase_sec_content(src);
buf = _strdup(sauv_secc);
for(ret = 0; (buf = strstr(buf, sec[SecStart])); ++ret, buf += strlen(sec[SecStart]));
@ -201,7 +201,7 @@ get_opt(char *src, char *def, char *name)
if(!src || !name)
return (def) ? str_to_opt(def) : ret;
if((p = opt_srch(erase_sec_content(src), name)))
if((p = opt_srch(sauv_secc, name)))
{
for(i = 0; p[i] && p[i] != '\n'; ++i);
p[i] = '\0';

View File

@ -67,6 +67,7 @@ char *erase_sec_content(char *buf);
char *opt_srch(char *buf, char *opt);
opt_type str_to_opt(char *str);
char *clean_value(char *str);
void set_current_sauv(char *str);
char **secname(char *name);
void free_secname(char **secname);
@ -80,4 +81,7 @@ opt_type *get_list_opt(char *src, char *def, char *name, int *n);
static const opt_type null_opt_type = {0, 0, 0, NULL};
char *sauv_delimc;
char *sauv_secc;
#endif /* CONFPARSE_H */

View File

@ -69,7 +69,7 @@ erase_sec_content(char *buf)
char *p, *str, *name, *ret;
char **sec;
if(!buf || !(str = erase_delim_content(buf)))
if(!buf || !(str = _strdup(sauv_delimc)))
return NULL;
ret = _strdup(buf);
@ -108,7 +108,7 @@ opt_srch(char *buf, char *opt)
if(!buf || !opt)
return NULL;
if((p = strstr(erase_delim_content(buf), opt)))
if((p = strstr(sauv_delimc /*erase_delim_content(buf)*/, opt)))
if((*(p + strlen(opt)) == ' ' || *(p + strlen(opt)) == '=')
&& (*(p - 1) == ' ' || *(p - 1) == '\n' || *(p - 1) == '\t' || !(*(p - 1))))
return _strdup(buf + (strlen(buf) - strlen(p)));
@ -164,6 +164,23 @@ clean_value(char *str)
return p;
}
void
set_current_sauv(char *str)
{
if(!str)
{
sauv_delimc = NULL;
sauv_secc = NULL;
return;
}
sauv_delimc = erase_delim_content(_strdup(str));
sauv_secc = erase_sec_content(_strdup(str));
return;
}
char**
secname(char *name)
{

View File

@ -862,17 +862,17 @@ layout_set_client_master(Client *c)
{
screen_get_sel();
if(!c
|| (c->flags & HintFlag)
|| !(c->flags & TileFlag)
|| (c->flags & FSSFlag))
if(!c || (c->flags & HintFlag) || !(c->flags & TileFlag)
|| (c->flags & FSSFlag))
return;
if(c == tiled_client(selscreen, clients))
CHECK((c = tiled_client(selscreen, c->next)));
client_detach(c);
client_attach(c);
client_focus(c);
tags[selscreen][seltag[selscreen]].layout.func(selscreen);
return;

View File

@ -357,7 +357,7 @@ typedef struct
uint resizecorner_normal;
uint resizecorner_focus;
uint mod;
MouseBinding *mouse;
MouseBinding *mouse;
int nmouse;
} client;
struct