diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/evas/src/modules/engines/software_x11/evas_xcb_xdefaults.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/evas/src/modules/engines/software_x11/evas_xcb_xdefaults.c')
-rw-r--r-- | libraries/evas/src/modules/engines/software_x11/evas_xcb_xdefaults.c | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/libraries/evas/src/modules/engines/software_x11/evas_xcb_xdefaults.c b/libraries/evas/src/modules/engines/software_x11/evas_xcb_xdefaults.c new file mode 100644 index 0000000..3a0bda5 --- /dev/null +++ b/libraries/evas/src/modules/engines/software_x11/evas_xcb_xdefaults.c | |||
@@ -0,0 +1,108 @@ | |||
1 | #include "evas_common.h" | ||
2 | #include "evas_xcb_xdefaults.h" | ||
3 | #include <fnmatch.h> | ||
4 | |||
5 | /* local function prototypes */ | ||
6 | static Eina_Bool _evas_xcb_xdefaults_glob_match(const char *str, const char *glob); | ||
7 | |||
8 | /* local variables */ | ||
9 | static Eina_File *_evas_xcb_xdefaults_file = NULL; | ||
10 | static char *_evas_xcb_xdefaults_data = NULL; | ||
11 | |||
12 | void | ||
13 | _evas_xcb_xdefaults_init(void) | ||
14 | { | ||
15 | char buff[PATH_MAX]; | ||
16 | |||
17 | snprintf(buff, sizeof(buff), "%s/.Xdefaults", getenv("HOME")); | ||
18 | if ((_evas_xcb_xdefaults_file = eina_file_open(buff, EINA_FALSE))) | ||
19 | { | ||
20 | eina_mmap_safety_enabled_set(EINA_TRUE); | ||
21 | |||
22 | _evas_xcb_xdefaults_data = | ||
23 | eina_file_map_all(_evas_xcb_xdefaults_file, EINA_FILE_SEQUENTIAL); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | void | ||
28 | _evas_xcb_xdefaults_shutdown(void) | ||
29 | { | ||
30 | if (!_evas_xcb_xdefaults_file) return; | ||
31 | if (_evas_xcb_xdefaults_data) | ||
32 | eina_file_map_free(_evas_xcb_xdefaults_file, _evas_xcb_xdefaults_data); | ||
33 | if (_evas_xcb_xdefaults_file) eina_file_close(_evas_xcb_xdefaults_file); | ||
34 | } | ||
35 | |||
36 | char * | ||
37 | _evas_xcb_xdefaults_string_get(const char *prog, const char *param) | ||
38 | { | ||
39 | char buff[1024], ret[1024]; | ||
40 | char *str = NULL; | ||
41 | char **ea = NULL; | ||
42 | unsigned int count = 0, i = 0; | ||
43 | |||
44 | if ((!_evas_xcb_xdefaults_data) || (!_evas_xcb_xdefaults_file)) | ||
45 | return NULL; | ||
46 | |||
47 | snprintf(buff, sizeof(buff), "*%s*.*%s*", prog, param); | ||
48 | |||
49 | str = _evas_xcb_xdefaults_data; | ||
50 | ea = eina_str_split_full(str, "\n", -1, &count); | ||
51 | for (i = 0; i < count; i++) | ||
52 | { | ||
53 | if (_evas_xcb_xdefaults_glob_match(ea[i], buff)) | ||
54 | sscanf(ea[i], "%*[^:]:%*[ ]%s", ret); | ||
55 | } | ||
56 | if ((ea) && (ea[0])) | ||
57 | { | ||
58 | free(ea[0]); | ||
59 | free(ea); | ||
60 | } | ||
61 | |||
62 | return strdup(ret); | ||
63 | } | ||
64 | |||
65 | int | ||
66 | _evas_xcb_xdefaults_int_get(const char *prog, const char *param) | ||
67 | { | ||
68 | char buff[1024]; | ||
69 | char *str = NULL; | ||
70 | char **ea = NULL; | ||
71 | unsigned int count = 0, i = 0; | ||
72 | int ret = -1; | ||
73 | |||
74 | if ((!_evas_xcb_xdefaults_data) || (!_evas_xcb_xdefaults_file)) | ||
75 | return 0; | ||
76 | |||
77 | snprintf(buff, sizeof(buff), "*%s*.*%s*", prog, param); | ||
78 | |||
79 | str = _evas_xcb_xdefaults_data; | ||
80 | ea = eina_str_split_full(str, "\n", -1, &count); | ||
81 | for (i = 0; i < count; i++) | ||
82 | { | ||
83 | if (_evas_xcb_xdefaults_glob_match(ea[i], buff)) | ||
84 | sscanf(ea[i], "%*[^:]:%*[ ]%d", &ret); | ||
85 | } | ||
86 | if ((ea) && (ea[0])) | ||
87 | { | ||
88 | free(ea[0]); | ||
89 | free(ea); | ||
90 | } | ||
91 | |||
92 | return ret; | ||
93 | } | ||
94 | |||
95 | /* local functions */ | ||
96 | static Eina_Bool | ||
97 | _evas_xcb_xdefaults_glob_match(const char *str, const char *glob) | ||
98 | { | ||
99 | if ((!str) || (!glob)) return EINA_FALSE; | ||
100 | if (glob[0] == 0) | ||
101 | { | ||
102 | if (str[0] == 0) return EINA_TRUE; | ||
103 | return EINA_FALSE; | ||
104 | } | ||
105 | if (!strcmp(glob, "*")) return EINA_TRUE; | ||
106 | if (!fnmatch(glob, str, 0)) return EINA_TRUE; | ||
107 | return EINA_FALSE; | ||
108 | } | ||