Confparse: Improve stuff and add wmfsrc_new, the next wmfs configuration file.
This commit is contained in:
125
src/config_new.c
125
src/config_new.c
@@ -30,55 +30,70 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config_struct.h"
|
||||
#include "wmfs.h"
|
||||
|
||||
void
|
||||
conf_init_func_list(void)
|
||||
func_name_list_t tmp_func_list[] =
|
||||
{
|
||||
int i;
|
||||
{"spawn", uicb_spawn },
|
||||
{"client_kill", uicb_client_kill },
|
||||
{"client_prev", uicb_client_prev },
|
||||
{"client_next", uicb_client_next },
|
||||
{"client_swap_next", uicb_client_swap_next },
|
||||
{"client_swap_prev", uicb_client_swap_prev },
|
||||
{"client_screen_next", uicb_client_screen_next },
|
||||
{"client_screen_prev", uicb_client_screen_prev },
|
||||
{"toggle_max", uicb_togglemax },
|
||||
{"layout_next", uicb_layout_next },
|
||||
{"layout_prev", uicb_layout_prev },
|
||||
{"tag", uicb_tag },
|
||||
{"tag_next", uicb_tag_next },
|
||||
{"tag_prev", uicb_tag_prev },
|
||||
{"tag_transfert", uicb_tagtransfert },
|
||||
{"set_mwfact", uicb_set_mwfact },
|
||||
{"set_nmaster", uicb_set_nmaster },
|
||||
{"quit", uicb_quit },
|
||||
{"toggle_infobar_position", uicb_infobar_togglepos },
|
||||
{"toggle_resizehint", uicb_toggle_resizehint },
|
||||
{"mouse_move", uicb_mouse_move },
|
||||
{"mouse_resize", uicb_mouse_resize },
|
||||
{"client_raise", uicb_client_raise },
|
||||
{"toggle_free", uicb_togglefree },
|
||||
{"screen_select", uicb_screen_select },
|
||||
{"screen_next", uicb_screen_next },
|
||||
{"screen_prev", uicb_screen_prev },
|
||||
{"reload", uicb_reload },
|
||||
{"launcher", uicb_launcher },
|
||||
{"set_layout", uicb_set_layout },
|
||||
{"menu", uicb_menu }
|
||||
};
|
||||
|
||||
func_name_list_t tmp_list[] =
|
||||
{
|
||||
{"spawn", uicb_spawn },
|
||||
{"client_kill", uicb_client_kill },
|
||||
{"client_prev", uicb_client_prev },
|
||||
{"client_next", uicb_client_next },
|
||||
{"client_swap_next", uicb_client_swap_next },
|
||||
{"client_swap_prev", uicb_client_swap_prev },
|
||||
{"client_screen_next", uicb_client_screen_next },
|
||||
{"client_screen_prev", uicb_client_screen_prev },
|
||||
{"toggle_max", uicb_togglemax },
|
||||
{"layout_next", uicb_layout_next },
|
||||
{"layout_prev", uicb_layout_prev },
|
||||
{"tag", uicb_tag },
|
||||
{"tag_next", uicb_tag_next },
|
||||
{"tag_prev", uicb_tag_prev },
|
||||
{"tag_transfert", uicb_tagtransfert },
|
||||
{"set_mwfact", uicb_set_mwfact },
|
||||
{"set_nmaster", uicb_set_nmaster },
|
||||
{"quit", uicb_quit },
|
||||
{"toggle_infobar_position", uicb_infobar_togglepos },
|
||||
{"toggle_resizehint", uicb_toggle_resizehint },
|
||||
{"mouse_move", uicb_mouse_move },
|
||||
{"mouse_resize", uicb_mouse_resize },
|
||||
{"client_raise", uicb_client_raise },
|
||||
{"toggle_free", uicb_togglefree },
|
||||
{"screen_select", uicb_screen_select },
|
||||
{"screen_next", uicb_screen_next },
|
||||
{"screen_prev", uicb_screen_prev },
|
||||
{"reload", uicb_reload },
|
||||
{"launcher", uicb_launcher },
|
||||
{"set_layout", uicb_set_layout },
|
||||
{"menu", uicb_menu }
|
||||
};
|
||||
key_name_list_t key_list[] =
|
||||
{
|
||||
{"Control", ControlMask },
|
||||
{"Shift", ShiftMask },
|
||||
{"Lock", LockMask },
|
||||
{"Alt", Mod1Mask },
|
||||
{"Mod2", Mod2Mask },
|
||||
{"Mod3", Mod3Mask },
|
||||
{"Mod4", Mod4Mask },
|
||||
{"Super", Mod4Mask },
|
||||
{"Mod5", Mod5Mask },
|
||||
{NULL, NoSymbol }
|
||||
};
|
||||
|
||||
func_list = emalloc(LEN(tmp_list), sizeof(func_name_list_t));
|
||||
|
||||
for(i = 0; i < LEN(tmp_list); ++i)
|
||||
func_list[i] = tmp_list[i];
|
||||
|
||||
return;
|
||||
}
|
||||
name_to_uint_t mouse_button_list[] =
|
||||
{
|
||||
{"Button1", Button1 },
|
||||
{"Button2", Button2 },
|
||||
{"Button3", Button3 },
|
||||
{"Button4", Button4 },
|
||||
{"Button5", Button5 },
|
||||
{"1", Button1 },
|
||||
{"2", Button2 },
|
||||
{"3", Button3 },
|
||||
{"4", Button4 },
|
||||
{"5", Button5 },
|
||||
};
|
||||
|
||||
void
|
||||
mouse_section(MouseBinding mb[], char *src, int ns)
|
||||
@@ -172,7 +187,6 @@ conf_client_section(char *src)
|
||||
|
||||
if((conf.client.nmouse = get_size_sec(src, "mouse")))
|
||||
{
|
||||
printf("conf.client.nmouse = %d\n", conf.client.nmouse);
|
||||
conf.client.mouse = emalloc(conf.client.nmouse, sizeof(MouseBinding));
|
||||
mouse_section(conf.client.mouse, src, conf.client.nmouse);
|
||||
}
|
||||
@@ -416,8 +430,8 @@ conf_menu_section(char *src)
|
||||
|
||||
if(!(conf.menu[i].place_at_mouse = get_opt(tmp, "true", "place_at_mouse").bool))
|
||||
{
|
||||
conf.menu[i].x = get_opt(cfgtmp, "0", "x").num;
|
||||
conf.menu[i].y = get_opt(cfgtmp, "0", "y").num;
|
||||
conf.menu[i].x = get_opt(tmp, "0", "x").num;
|
||||
conf.menu[i].y = get_opt(tmp, "0", "y").num;
|
||||
}
|
||||
|
||||
conf.menu[i].colors.focus.bg = getcolor(get_opt(tmp, "#000000", "bg_focus").str);
|
||||
@@ -487,7 +501,7 @@ conf_keybind_section(char *src)
|
||||
|
||||
if(keys[i].func == NULL)
|
||||
{
|
||||
fprintf(stderr, "WMFS Configuration error: Unknow Function \"%s\"\n", get_opt(tmp, "", "func").str);
|
||||
fprintf(stderr, "WMFS Configuration warning: Unknow Function \"%s\"\n", get_opt(tmp, "", "func").str);
|
||||
keys[i].func = uicb_spawn;
|
||||
}
|
||||
keys[i].cmd = (!get_opt(tmp, "", "cmd").str) ? NULL : get_opt(tmp, "", "cmd").str;
|
||||
@@ -502,22 +516,19 @@ conf_keybind_section(char *src)
|
||||
void
|
||||
init_conf(void)
|
||||
{
|
||||
FILE *f;
|
||||
char *file;
|
||||
|
||||
if(!(f = fopen(conf.confpath, "r")))
|
||||
if(!(file = file_to_str(conf.confpath)))
|
||||
{
|
||||
fprintf(stderr, "WMFS: parsing configuration file (%s) failed\n", conf.confpath);
|
||||
sprintf(conf.confpath, "%s/wmfs/wmfsrc", XDG_CONFIG_DIR);
|
||||
fprintf(stderr, "Use the default configuration (%s).\n", conf.confpath);
|
||||
f = fopen(conf.confpath, "r");
|
||||
file = file_to_str(conf.confpath);
|
||||
}
|
||||
|
||||
file = file_to_str(f);
|
||||
|
||||
conf_init_func_list();
|
||||
|
||||
/* conf_alias_section(get_sec(file, "alias")); */
|
||||
/* Set func_list */
|
||||
func_list = emalloc(LEN(tmp_func_list), sizeof(func_name_list_t));
|
||||
memcpy(func_list, tmp_func_list, LEN(tmp_func_list) * sizeof(func_name_list_t));
|
||||
|
||||
conf_misc_section(get_sec(file, "misc"));
|
||||
conf_bar_section(get_sec(file, "bar"));
|
||||
|
||||
@@ -33,21 +33,26 @@
|
||||
#include "confparse.h"
|
||||
|
||||
char*
|
||||
file_to_str(FILE *f)
|
||||
file_to_str(char *path)
|
||||
{
|
||||
char c;
|
||||
char *ret;
|
||||
int i;
|
||||
char *ret, *p;
|
||||
int fd, i;
|
||||
struct stat st;
|
||||
|
||||
for(i = 1; fgetc(f) != EOF; ++i);
|
||||
if(!path || !(fd = open(path, O_RDONLY)))
|
||||
return NULL;
|
||||
|
||||
ret = emalloc(i, sizeof(char));
|
||||
/* To get the file size */
|
||||
stat(path, &st);
|
||||
|
||||
rewind(f);
|
||||
/* Bufferize file */
|
||||
ret = _strdup((char*)mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, SEEK_SET));
|
||||
|
||||
for(i = 0; (c = fgetc(f)) != EOF; ret[i++] = c);
|
||||
/* Erase comment line from return value */
|
||||
for(i = 0; (p = strchr(erase_delim_content(ret + i), COMMENT_CHAR));)
|
||||
for(i = st.st_size - strlen(p); ret[i] && ret[i] != '\n'; ret[i++] = ' ');
|
||||
|
||||
fclose(f);
|
||||
fprintf(stderr, "WMFS Configuration info: '%s' read.\n", path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -108,7 +113,7 @@ get_nsec(char *src, char *name, int n)
|
||||
buf = erase_delim_content(src);
|
||||
buf2 = erase_sec_content(buf);
|
||||
|
||||
for(i = 0; i < n * 2 && (buf = strstr(buf, secn)); ++i, buf += strlen(secn));
|
||||
for(i = 0; i < (n * 2) && (buf = strstr(buf, secn)); ++i, buf += strlen(secn));
|
||||
|
||||
ret = get_sec(src + strlen(src) - strlen(buf), name);
|
||||
|
||||
@@ -181,11 +186,11 @@ get_list_opt(char *src, char *def, char *name, int *n)
|
||||
if(!(p = get_opt(src, def, name).str))
|
||||
return NULL;
|
||||
|
||||
for(i = 0; p[i] && (p[i] != '}' || is_in_delimiter(p, i)); ++i);
|
||||
for(i = 0; p[i] && (p[i] != LIST_DEL_E || is_in_delimiter(p, i)); ++i);
|
||||
p[i + 1] = '\0';
|
||||
|
||||
/* Syntax of list (val1, val2, ..., valx) */
|
||||
if(*p != '{' || *(p + strlen(p) - 1) != '}')
|
||||
/* Syntax of list {val1, val2, ..., valx} */
|
||||
if(*p != LIST_DEL_S || *(p + strlen(p) - 1) != LIST_DEL_E)
|
||||
return NULL;
|
||||
|
||||
/* Erase ( ) */
|
||||
@@ -215,10 +220,8 @@ get_list_opt(char *src, char *def, char *name, int *n)
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = emalloc(1, sizeof(opt_type));
|
||||
ret = emalloc((*n = 1), sizeof(opt_type));
|
||||
*ret = str_to_opt(clean_value(p));
|
||||
|
||||
*n = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -33,15 +33,23 @@
|
||||
#ifndef CONFPARSE_H
|
||||
#define CONFPARSE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "../wmfs.h"
|
||||
|
||||
/* Section delimiter */
|
||||
#define SEC_DEL_S '['
|
||||
#define SEC_DEL_E ']'
|
||||
|
||||
/* List delimiter */
|
||||
#define LIST_DEL_S '{'
|
||||
#define LIST_DEL_E '}'
|
||||
|
||||
/* Comment character */
|
||||
#define COMMENT_CHAR '#'
|
||||
|
||||
typedef struct
|
||||
{
|
||||
long int num;
|
||||
@@ -59,7 +67,7 @@ opt_type str_to_opt(char *str);
|
||||
char *clean_value(char *str);
|
||||
|
||||
/* confparse.c */
|
||||
char *file_to_str(FILE *f);
|
||||
char *file_to_str(char *path);
|
||||
char *get_sec(char *src, char *name);
|
||||
char *get_nsec(char *src, char *name, int n);
|
||||
int get_size_sec(char *src, char *name);
|
||||
|
||||
@@ -38,15 +38,13 @@ erase_delim_content(char *buf)
|
||||
int i, j;
|
||||
char *str, c;
|
||||
|
||||
if(!buf)
|
||||
if(!buf || !(str = _strdup(buf)))
|
||||
return NULL;
|
||||
|
||||
str = _strdup(buf);
|
||||
|
||||
for(i = 0; i < strlen(str); ++i)
|
||||
if((c = str[i]) == '"' || (c = str[i]) == '\'')
|
||||
{
|
||||
for(str[(j = i)] = ' '; str[j] && str[j] != c; str[j++] = ' ');
|
||||
for(*(str + (j = i)) = ' '; str[j] && str[j] != c; str[j++] = ' ');
|
||||
str[j] = ' ';
|
||||
}
|
||||
|
||||
@@ -70,10 +68,9 @@ erase_sec_content(char *buf)
|
||||
int i, j;
|
||||
char *p, *str, *name, *ret;
|
||||
|
||||
if(!buf)
|
||||
if(!buf || !(str = erase_delim_content(buf)))
|
||||
return NULL;
|
||||
|
||||
str = erase_delim_content(buf);
|
||||
ret = _strdup(buf);
|
||||
|
||||
for(i = 1, name = _strdup(str + i); strchr(str + i, SEC_DEL_S); ++i, name = _strdup(str + i))
|
||||
@@ -97,20 +94,15 @@ erase_sec_content(char *buf)
|
||||
char*
|
||||
opt_srch(char *buf, char *opt)
|
||||
{
|
||||
char *p, c1, c2;
|
||||
char *p;
|
||||
|
||||
if(!buf || !opt)
|
||||
return NULL;
|
||||
|
||||
if((p = strstr(erase_delim_content(buf), opt)))
|
||||
{
|
||||
c1 = *(p + strlen(opt));
|
||||
c2 = *(p - 1);
|
||||
|
||||
if((c1 == ' ' || c1 == '=')
|
||||
&& (c2 == ' ' || c2 == '\n' || c2 == '\t' || !c2))
|
||||
return _strdup(buf + (strlen(buf) - strlen(p)));
|
||||
}
|
||||
if((*(p + strlen(opt)) == ' ' || *(p + strlen(opt)) == '=')
|
||||
&& (*(p - 1) == ' ' || *(p - 1) == '\n' || *(p - 1) == '\t' || !(*(p - 1))))
|
||||
return _strdup(buf + (strlen(buf) - strlen(p)));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -146,18 +138,15 @@ clean_value(char *str)
|
||||
int i;
|
||||
char c, *p;
|
||||
|
||||
if(!str)
|
||||
if(!str || !(p = _strdup(str)))
|
||||
return NULL;
|
||||
|
||||
p = _strdup(str);
|
||||
|
||||
/* Remove useless spaces */
|
||||
for(; *p == ' '; ++p);
|
||||
for(; *(p + strlen(p) - 1) == ' '; *(p + strlen(p) - 1) = '\0');
|
||||
|
||||
/* For string delimiter (" or ') */
|
||||
if(((c = *p) == '"' || (c = *p) == '\'')
|
||||
&& strchr(p + 1, c))
|
||||
if(((c = *p) == '"' || (c = *p) == '\'') && strchr(p + 1, c))
|
||||
{
|
||||
for(++p, i = 0; p[i] && p[i] != c; ++i);
|
||||
p[i] = '\0';
|
||||
|
||||
10
src/wmfs.h
10
src/wmfs.h
@@ -52,6 +52,7 @@
|
||||
#include <X11/Xft/Xft.h>
|
||||
|
||||
/* Local headers */
|
||||
#include "confparse/confparse.h"
|
||||
#include "config.h"
|
||||
#include "structs.h"
|
||||
|
||||
@@ -195,15 +196,6 @@ void frame_moveresize(Client *c, XRectangle geo);
|
||||
void frame_update(Client *c);
|
||||
|
||||
/* config.c */
|
||||
void conf_alias_section(cfg_t *cfg_a);
|
||||
void conf_misc_section(cfg_t *cfg_m);
|
||||
void conf_bar_section(cfg_t *cfg_b);
|
||||
void conf_root_section(cfg_t *cfg_r);
|
||||
void conf_client_section(cfg_t *cfg_c);
|
||||
void conf_layout_section(cfg_t *cfg_l);
|
||||
void conf_tag_section(cfg_t *cfg_t);
|
||||
void conf_menu_section(cfg_t *cfg_m);
|
||||
void conf_keybind_section(cfg_t *cfg_k);
|
||||
void init_conf(void);
|
||||
|
||||
/* event.c */
|
||||
|
||||
Reference in New Issue
Block a user