summaryrefslogtreecommitdiff
path: root/legacy/efreet
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-10-09 20:16:29 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-10-09 20:16:29 +0000
commita13620d1e725b3f4f69c75e753984dd4e5528374 (patch)
tree69ac9fba750e666c4514701cfd6dbbbe1b1df9e5 /legacy/efreet
parent7869bcc670ed8a4935319d491fdf0f8639f16852 (diff)
add efreet_user_dir to test variables.
SVN revision: 77683
Diffstat (limited to 'legacy/efreet')
-rw-r--r--legacy/efreet/src/tests/Makefile.am6
-rw-r--r--legacy/efreet/src/tests/efreet_user_dir.c276
2 files changed, 281 insertions, 1 deletions
diff --git a/legacy/efreet/src/tests/Makefile.am b/legacy/efreet/src/tests/Makefile.am
index 13c1274166..1eae154153 100644
--- a/legacy/efreet/src/tests/Makefile.am
+++ b/legacy/efreet/src/tests/Makefile.am
@@ -16,7 +16,8 @@ bin_PROGRAMS = \
16efreet_test \ 16efreet_test \
17efreet_spec_test \ 17efreet_spec_test \
18efreet_cache_test \ 18efreet_cache_test \
19efreet_icon_cache_dump 19efreet_icon_cache_dump \
20efreet_user_dir
20 21
21efreet_test_LDADD = $(top_builddir)/src/lib/libefreet.la \ 22efreet_test_LDADD = $(top_builddir)/src/lib/libefreet.la \
22 $(top_builddir)/src/lib/libefreet_mime.la \ 23 $(top_builddir)/src/lib/libefreet_mime.la \
@@ -64,3 +65,6 @@ $(top_builddir)/src/lib/libefreet.la \
64 65
65efreet_icon_cache_dump_SOURCES = \ 66efreet_icon_cache_dump_SOURCES = \
66efreet_icon_cache_dump.c 67efreet_icon_cache_dump.c
68
69efreet_user_dir_SOURCES = efreet_user_dir.c
70efreet_user_dir_LDADD = $(top_builddir)/src/lib/libefreet.la @EFREET_LIBS@
diff --git a/legacy/efreet/src/tests/efreet_user_dir.c b/legacy/efreet/src/tests/efreet_user_dir.c
new file mode 100644
index 0000000000..3c4bd60b7b
--- /dev/null
+++ b/legacy/efreet/src/tests/efreet_user_dir.c
@@ -0,0 +1,276 @@
1#include <Efreet.h>
2
3static void
4_print_data_home(void)
5{
6 const char *s = efreet_data_home_get();
7 if (!s) return;
8 fputs(s, stdout);
9}
10
11static void
12_print_data_dirs(void)
13{
14 const Eina_List *itr, *lst = efreet_data_dirs_get();
15 const char *s;
16 Eina_Bool first = EINA_TRUE;
17
18 EINA_LIST_FOREACH(lst, itr, s)
19 {
20 if (first)
21 first = EINA_FALSE;
22 else
23 putchar(':');
24 fputs(s, stdout);
25 }
26}
27
28static void
29_print_config_home(void)
30{
31 const char *s = efreet_config_home_get();
32 if (!s) return;
33 fputs(s, stdout);
34}
35
36static void
37_print_config_dirs(void)
38{
39 const Eina_List *itr, *lst = efreet_config_dirs_get();
40 const char *s;
41 Eina_Bool first = EINA_TRUE;
42
43 EINA_LIST_FOREACH(lst, itr, s)
44 {
45 if (first)
46 first = EINA_FALSE;
47 else
48 putchar(':');
49 fputs(s, stdout);
50 }
51}
52
53static void
54_print_cache_home(void)
55{
56 const char *s = efreet_cache_home_get();
57 if (!s) return;
58 fputs(s, stdout);
59}
60
61static void
62_print_runtime_dir(void)
63{
64 const char *s = efreet_runtime_dir_get();
65 if (!s) return;
66 fputs(s, stdout);
67}
68
69static void
70_print_desktop_dir(void)
71{
72 const char *s = efreet_desktop_dir_get();
73 if (!s) return;
74 fputs(s, stdout);
75}
76
77static void
78_print_download_dir(void)
79{
80 const char *s = efreet_download_dir_get();
81 if (!s) return;
82 fputs(s, stdout);
83}
84
85static void
86_print_templates_dir(void)
87{
88 const char *s = efreet_templates_dir_get();
89 if (!s) return;
90 fputs(s, stdout);
91}
92
93static void
94_print_public_share_dir(void)
95{
96 const char *s = efreet_public_share_dir_get();
97 if (!s) return;
98 fputs(s, stdout);
99}
100
101static void
102_print_documents_dir(void)
103{
104 const char *s = efreet_documents_dir_get();
105 if (!s) return;
106 fputs(s, stdout);
107}
108
109static void
110_print_music_dir(void)
111{
112 const char *s = efreet_music_dir_get();
113 if (!s) return;
114 fputs(s, stdout);
115}
116
117static void
118_print_pictures_dir(void)
119{
120 const char *s = efreet_pictures_dir_get();
121 if (!s) return;
122 fputs(s, stdout);
123}
124
125static void
126_print_videos_dir(void)
127{
128 const char *s = efreet_videos_dir_get();
129 if (!s) return;
130 fputs(s, stdout);
131}
132
133struct var_alias {
134 const char *alias;
135 const char *name;
136};
137
138struct var_print {
139 const char *name;
140 void (*print)(void);
141};
142
143static const struct var_alias aliases[] = {
144 {"DATA_HOME", "XDG_DATA_HOME"},
145 {"DATA_DIRS", "XDG_DATA_DIRS"},
146 {"CONFIG_HOME", "XDG_CONFIG_HOME"},
147 {"CONFIG_DIRS", "XDG_CONFIG_DIRS"},
148 {"CACHE_HOME", "XDG_CACHE_HOME"},
149 {"RUNTIME_DIR", "XDG_RUNTIME_DIR"},
150 {"DESKTOP", "XDG_DESKTOP_DIR"},
151 {"DOWNLOAD", "XDG_DOWNLOAD_DIR"},
152 {"TEMPLATES", "XDG_TEMPLATES_DIR"},
153 {"PUBLICSHARE", "XDG_PUBLICSHARE_DIR"},
154 {"DOCUMENTS", "XDG_DOCUMENTS_DIR"},
155 {"MUSIC", "XDG_MUSIC_DIR"},
156 {"PICTURES", "XDG_PICTURES_DIR"},
157 {"VIDEOS", "XDG_VIDEOS_DIR"},
158 {NULL, NULL}
159};
160
161static const struct var_print printers[] = {
162 {"XDG_DATA_HOME", _print_data_home},
163 {"XDG_DATA_DIRS", _print_data_dirs},
164 {"XDG_CONFIG_HOME", _print_config_home},
165 {"XDG_CONFIG_DIRS", _print_config_dirs},
166 {"XDG_CACHE_HOME", _print_cache_home},
167 {"XDG_RUNTIME_DIR", _print_runtime_dir},
168 {"XDG_DESKTOP_DIR", _print_desktop_dir},
169 {"XDG_DOWNLOAD_DIR", _print_download_dir},
170 {"XDG_TEMPLATES_DIR", _print_templates_dir},
171 {"XDG_PUBLICSHARE_DIR", _print_public_share_dir},
172 {"XDG_DOCUMENTS_DIR", _print_documents_dir},
173 {"XDG_MUSIC_DIR", _print_music_dir},
174 {"XDG_PICTURES_DIR", _print_pictures_dir},
175 {"XDG_VIDEOS_DIR", _print_videos_dir},
176 {NULL, NULL}
177};
178
179static void
180_print_do(const struct var_print *itr)
181{
182 printf("%s=", itr->name);
183 itr->print();
184 putchar('\n');
185}
186
187static const struct var_print *
188_resolve_printer(const char *alias)
189{
190 const struct var_print *p = printers;
191 const struct var_alias *a;
192
193 for (; p->name != NULL; p++)
194 if (strcmp(p->name, alias) == 0)
195 return p;
196
197 for (a = aliases; a->alias != NULL; a++)
198 if (strcmp(a->alias, alias) == 0)
199 {
200 for (p = printers; p->name != NULL; p++)
201 if (strcmp(p->name, a->name) == 0)
202 return p;
203 return NULL;
204 }
205
206 return NULL;
207}
208
209static void
210_print(const char *alias)
211{
212 const struct var_print *itr = _resolve_printer(alias);
213
214 if (!itr)
215 {
216 fprintf(stderr, "ERROR: unknown variable %s\n", alias);
217 return;
218 }
219
220 _print_do(itr);
221}
222
223static void
224_print_all(void)
225{
226 const struct var_print *itr = printers;
227 for (; itr->name != NULL; itr++)
228 _print_do(itr);
229}
230
231static void
232_help(const char *prog)
233{
234 const struct var_print *itr = printers;
235
236 printf("Usage:\n\n"
237 "\t%s [varname1] ... [varnameN]\n\n"
238 "Where varnameN is one of:\n",
239 prog);
240
241 for (; itr->name != NULL; itr++)
242 printf("\t%s\n", itr->name);
243 putchar('\n');
244}
245
246int
247main(int argc, char *argv[])
248{
249 if (!efreet_init())
250 {
251 fputs("ERROR: Could not initialize efreet!\n", stderr);
252 return EXIT_FAILURE;
253 }
254
255 if (argc < 2)
256 _print_all();
257 else
258 {
259 int i;
260
261 for (i = 1; i < argc; i++)
262 if ((strcmp(argv[i], "-h") == 0) ||
263 (strcmp(argv[i], "--help") == 0))
264 {
265 _help(argv[0]);
266 goto end;
267 }
268
269 for (i = 1; i < argc; i++)
270 _print(argv[i]);
271 }
272
273 end:
274 efreet_shutdown();
275 return EXIT_SUCCESS;
276}