summaryrefslogtreecommitdiff
path: root/src/bin/exactness
diff options
context:
space:
mode:
authorStefan Schmidt <s.schmidt@samsung.com>2020-03-17 16:53:30 +0100
committerStefan Schmidt <s.schmidt@samsung.com>2020-03-20 12:04:35 +0100
commitb84694f5189f86e223c68695366c0d676d8fc6a4 (patch)
tree402a74ecd7daeb4f9fbc24bc6f0a40a3900deb67 /src/bin/exactness
parentb5c24af2e14c9a56dbba0f61119281c06da66758 (diff)
exactness: factour out the program invoke code
It needs a little special case handling for the player (to load the edj file), but the rest is really the same. Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D11460
Diffstat (limited to 'src/bin/exactness')
-rw-r--r--src/bin/exactness/common.c86
-rw-r--r--src/bin/exactness/common.h4
-rw-r--r--src/bin/exactness/player.c92
-rw-r--r--src/bin/exactness/recorder.c88
4 files changed, 94 insertions, 176 deletions
diff --git a/src/bin/exactness/common.c b/src/bin/exactness/common.c
index 17983cdbc6..4d770eb584 100644
--- a/src/bin/exactness/common.c
+++ b/src/bin/exactness/common.c
@@ -12,3 +12,89 @@ ex_printf(int verbose, const char *fmt, ...)
12 vprintf(fmt, ap); 12 vprintf(fmt, ap);
13 va_end(ap); 13 va_end(ap);
14} 14}
15
16int
17ex_prg_invoke(const char *full_path, int argc, char **argv, Eina_Bool player)
18{
19 Eina_Value *ret__;
20 int real__;
21
22 void (*efl_main)(void *data, const Efl_Event *ev);
23 int (*elm_main)(int argc, char **argv);
24 int (*c_main)(int argc, char **argv);
25 Eina_Module *h = eina_module_new(full_path);
26 if (!h || !eina_module_load(h))
27 {
28 fprintf(stderr, "Failed loading %s.\n", full_path);
29 if (h) eina_module_free(h);
30 return 1;
31 }
32 efl_main = eina_module_symbol_get(h, "efl_main");
33 elm_main = eina_module_symbol_get(h, "elm_main");
34 c_main = eina_module_symbol_get(h, "main");
35 _evas_new = eina_module_symbol_get(h, "evas_new");
36 if (!_evas_new)
37 {
38 fprintf(stderr, "Failed loading symbol 'evas_new' from %s.\n", full_path);
39 eina_module_free(h);
40 return 1;
41 }
42 if (efl_main)
43 {
44 elm_init(argc, argv);
45 if (player) elm_theme_overlay_add(NULL, DATA_DIR"/exactness_play.edj");
46 efl_event_callback_add(efl_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS, efl_main, NULL);
47 ret__ = efl_loop_begin(efl_main_loop_get());
48 real__ = efl_loop_exit_code_process(ret__);
49 elm_shutdown();
50 }
51 else if (elm_main)
52 {
53 elm_init(argc, argv);
54 if (player) elm_theme_overlay_add(NULL, DATA_DIR"/exactness_play.edj");
55 real__ = elm_main(argc, argv);
56 elm_shutdown();
57 }
58 else if (c_main)
59 {
60 real__ = c_main(argc, argv);
61 }
62 else
63 {
64 fprintf(stderr, "Failed loading symbol 'efl_main', 'elm_main' or 'main' from %s.\n", full_path);
65 eina_module_free(h);
66 real__ = 1;
67 }
68 return real__;
69}
70
71Eina_Stringshare *
72ex_prg_full_path_guess(const char *prg)
73{
74 char full_path[PATH_MAX];
75 if (strchr(prg, '/')) return eina_stringshare_add(prg);
76 char *env_path = eina_strdup(getenv("PATH"));
77 Eina_Stringshare *ret = NULL;
78 char *paths = env_path;
79
80 while (paths && *paths && !ret)
81 {
82 char *real_path;
83 char *colon = strchr(paths, ':');
84 if (colon) *colon = '\0';
85
86 sprintf(full_path, "%s/%s", paths, prg);
87 real_path = ecore_file_realpath(full_path);
88 if (*real_path)
89 {
90 ret = eina_stringshare_add(real_path);
91 // check if executable
92 }
93 free(real_path);
94
95 paths += strlen(paths);
96 if (colon) paths++;
97 }
98 free(env_path);
99 return ret;
100}
diff --git a/src/bin/exactness/common.h b/src/bin/exactness/common.h
index 2581c63392..b3bb2da8c1 100644
--- a/src/bin/exactness/common.h
+++ b/src/bin/exactness/common.h
@@ -97,4 +97,8 @@ foo(Eina_Debug_Session *session, int srcid, void *buffer, int size) \
97 _buf += __len; \ 97 _buf += __len; \
98} 98}
99 99
100Evas *(*_evas_new)(void);
101
100void ex_printf(int verbose, const char *fmt, ...); 102void ex_printf(int verbose, const char *fmt, ...);
103int ex_prg_invoke(const char *full_path, int argc, char **argv, Eina_Bool player);
104Eina_Stringshare *ex_prg_full_path_guess(const char *prg);
diff --git a/src/bin/exactness/player.c b/src/bin/exactness/player.c
index fa9f0c63d3..ff500fcd8d 100644
--- a/src/bin/exactness/player.c
+++ b/src/bin/exactness/player.c
@@ -56,7 +56,6 @@ static Exactness_Unit *_src_unit = NULL;
56static const char *_test_name = NULL; 56static const char *_test_name = NULL;
57static int _verbose = 0; 57static int _verbose = 0;
58 58
59static Evas *(*_evas_new)(void) = NULL;
60static Eina_List *_evas_list = NULL; 59static Eina_List *_evas_list = NULL;
61 60
62static Eina_List *_cur_event_list = NULL; 61static Eina_List *_cur_event_list = NULL;
@@ -804,94 +803,6 @@ _src_open()
804 return EINA_TRUE; 803 return EINA_TRUE;
805} 804}
806 805
807static int
808_prg_invoke(const char *full_path, int argc, char **argv)
809{
810 Eina_Value *ret__;
811 int real__;
812
813 void (*efl_main)(void *data, const Efl_Event *ev);
814 int (*elm_main)(int argc, char **argv);
815 int (*c_main)(int argc, char **argv);
816 Eina_Module *h = eina_module_new(full_path);
817 if (!h || !eina_module_load(h))
818 {
819 fprintf(stderr, "Failed loading %s.\n", full_path);
820 if (h) eina_module_free(h);
821 return 1;
822 }
823 efl_main = eina_module_symbol_get(h, "efl_main");
824 elm_main = eina_module_symbol_get(h, "elm_main");
825 c_main = eina_module_symbol_get(h, "main");
826 _evas_new = eina_module_symbol_get(h, "evas_new");
827 if (!_evas_new)
828 {
829 fprintf(stderr, "Failed loading symbol 'evas_new' from %s.\n", full_path);
830 eina_module_free(h);
831 return 1;
832 }
833
834 if (efl_main)
835 {
836 elm_init(argc, argv);
837 elm_theme_overlay_add(NULL, DATA_DIR"/exactness_play.edj");
838 efl_event_callback_add(efl_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS, efl_main, NULL);
839 ret__ = efl_loop_begin(efl_main_loop_get());
840 real__ = efl_loop_exit_code_process(ret__);
841 elm_shutdown();
842 }
843 else if (elm_main)
844 {
845 elm_init(argc, argv);
846 elm_theme_overlay_add(NULL, DATA_DIR"/exactness_play.edj");
847 real__ = elm_main(argc, argv);
848 elm_shutdown();
849 }
850 else if (c_main)
851 {
852 real__ = c_main(argc, argv);
853 }
854 else
855 {
856 fprintf(stderr, "Failed loading symbol 'efl_main', 'elm_main' or 'main' from %s.\n", full_path);
857 eina_module_free(h);
858 real__ = 1;
859 }
860
861 return real__;
862}
863
864static Eina_Stringshare *
865_prg_full_path_guess(const char *prg)
866{
867 char full_path[PATH_MAX];
868 if (strchr(prg, '/')) return eina_stringshare_add(prg);
869 char *env_path = eina_strdup(getenv("PATH"));
870 Eina_Stringshare *ret = NULL;
871 char *paths = env_path;
872
873 while (paths && *paths && !ret)
874 {
875 char *real_path;
876 char *colon = strchr(paths, ':');
877 if (colon) *colon = '\0';
878
879 sprintf(full_path, "%s/%s", paths, prg);
880 real_path = ecore_file_realpath(full_path);
881 if (*real_path)
882 {
883 ret = eina_stringshare_add(real_path);
884 // check if executable
885 }
886 free(real_path);
887
888 paths += strlen(paths);
889 if (colon) paths++;
890 }
891 free(env_path);
892 return ret;
893}
894
895static Eina_Bool 806static Eina_Bool
896_mkdir(const char *path, Eina_Bool skip_last) 807_mkdir(const char *path, Eina_Bool skip_last)
897{ 808{
@@ -1022,6 +933,7 @@ int main(int argc, char **argv)
1022 const char *chosen_fonts = NULL; 933 const char *chosen_fonts = NULL;
1023 Eina_Bool show_on_screen = EINA_FALSE; 934 Eina_Bool show_on_screen = EINA_FALSE;
1024 Eina_Bool want_quit = EINA_FALSE, external_injection = EINA_FALSE; 935 Eina_Bool want_quit = EINA_FALSE, external_injection = EINA_FALSE;
936 _evas_new = NULL;
1025 937
1026 Ecore_Getopt_Value values[] = { 938 Ecore_Getopt_Value values[] = {
1027 ECORE_GETOPT_VALUE_STR(dest), 939 ECORE_GETOPT_VALUE_STR(dest),
@@ -1255,7 +1167,7 @@ int main(int argc, char **argv)
1255 ecore_evas_callback_new_set(_my_evas_new); 1167 ecore_evas_callback_new_set(_my_evas_new);
1256 if (_src_type != FTYPE_REMOTE) 1168 if (_src_type != FTYPE_REMOTE)
1257 ecore_idler_add(_src_feed, NULL); 1169 ecore_idler_add(_src_feed, NULL);
1258 pret = _prg_invoke(_prg_full_path_guess(argv[0]), argc - opt_args, argv); 1170 pret = ex_prg_invoke(ex_prg_full_path_guess(argv[0]), argc - opt_args, argv, EINA_TRUE);
1259 1171
1260 if (_dest && _dest_unit) 1172 if (_dest && _dest_unit)
1261 { 1173 {
diff --git a/src/bin/exactness/recorder.c b/src/bin/exactness/recorder.c
index f8eefe591e..965a88fb24 100644
--- a/src/bin/exactness/recorder.c
+++ b/src/bin/exactness/recorder.c
@@ -29,7 +29,6 @@
29#define SHOT_KEY_STR "F2" 29#define SHOT_KEY_STR "F2"
30#define SAVE_KEY_STR "F3" 30#define SAVE_KEY_STR "F3"
31 31
32static Evas *(*_evas_new)(void) = NULL;
33static const char *_out_filename = NULL; 32static const char *_out_filename = NULL;
34static const char *_test_name = NULL; 33static const char *_test_name = NULL;
35static int _verbose = 0; 34static int _verbose = 0;
@@ -236,90 +235,6 @@ _my_evas_new(int w EINA_UNUSED, int h EINA_UNUSED)
236 return e; 235 return e;
237} 236}
238 237
239static int
240_prg_invoke(const char *full_path, int argc, char **argv)
241{
242 Eina_Value *ret__;
243 int real__;
244
245 void (*efl_main)(void *data, const Efl_Event *ev);
246 int (*elm_main)(int argc, char **argv);
247 int (*c_main)(int argc, char **argv);
248 Eina_Module *h = eina_module_new(full_path);
249 if (!h || !eina_module_load(h))
250 {
251 fprintf(stderr, "Failed loading %s.\n", full_path);
252 if (h) eina_module_free(h);
253 return EINA_FALSE;
254 }
255 efl_main = eina_module_symbol_get(h, "efl_main");
256 elm_main = eina_module_symbol_get(h, "elm_main");
257 c_main = eina_module_symbol_get(h, "main");
258 _evas_new = eina_module_symbol_get(h, "evas_new");
259 if (!_evas_new)
260 {
261 fprintf(stderr, "Failed loading symbol 'evas_new' from %s.\n", full_path);
262 eina_module_free(h);
263 return 1;
264 }
265 if (efl_main)
266 {
267 elm_init(argc, argv);
268 efl_event_callback_add(efl_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS, efl_main, NULL);
269 ret__ = efl_loop_begin(efl_main_loop_get());
270 real__ = efl_loop_exit_code_process(ret__);
271 elm_shutdown();
272 }
273 else if (elm_main)
274 {
275 elm_init(argc, argv);
276 real__ = elm_main(argc, argv);
277 elm_shutdown();
278 }
279 else if (c_main)
280 {
281 real__ = c_main(argc, argv);
282 }
283 else
284 {
285 fprintf(stderr, "Failed loading symbol 'efl_main', 'elm_main' or 'main' from %s.\n", full_path);
286 eina_module_free(h);
287 real__ = 1;
288 }
289 return real__;
290}
291
292static Eina_Stringshare *
293_prg_full_path_guess(const char *prg)
294{
295 char full_path[PATH_MAX];
296 if (strchr(prg, '/')) return eina_stringshare_add(prg);
297 char *env_path = eina_strdup(getenv("PATH"));
298 Eina_Stringshare *ret = NULL;
299 char *paths = env_path;
300
301 while (paths && *paths && !ret)
302 {
303 char *real_path;
304 char *colon = strchr(paths, ':');
305 if (colon) *colon = '\0';
306
307 sprintf(full_path, "%s/%s", paths, prg);
308 real_path = ecore_file_realpath(full_path);
309 if (*real_path)
310 {
311 ret = eina_stringshare_add(real_path);
312 // check if executable
313 }
314 free(real_path);
315
316 paths += strlen(paths);
317 if (colon) paths++;
318 }
319 free(env_path);
320 return ret;
321}
322
323static Eina_Bool 238static Eina_Bool
324_mkdir(const char *dir) 239_mkdir(const char *dir)
325{ 240{
@@ -370,6 +285,7 @@ int main(int argc, char **argv)
370 char *fonts_dir = NULL; 285 char *fonts_dir = NULL;
371 int pret = 1, opt_args = 0; 286 int pret = 1, opt_args = 0;
372 Eina_Bool want_quit = EINA_FALSE; 287 Eina_Bool want_quit = EINA_FALSE;
288 _evas_new = NULL;
373 289
374 Ecore_Getopt_Value values[] = { 290 Ecore_Getopt_Value values[] = {
375 ECORE_GETOPT_VALUE_STR(dest), 291 ECORE_GETOPT_VALUE_STR(dest),
@@ -500,7 +416,7 @@ int main(int argc, char **argv)
500 416
501 ecore_evas_callback_new_set(_my_evas_new); 417 ecore_evas_callback_new_set(_my_evas_new);
502 _last_timestamp = ecore_time_get() * 1000; 418 _last_timestamp = ecore_time_get() * 1000;
503 pret = _prg_invoke(_prg_full_path_guess(argv[0]), argc - opt_args, argv); 419 pret = ex_prg_invoke(ex_prg_full_path_guess(argv[0]), argc - opt_args, argv, EINA_FALSE);
504 420
505 _output_write(); 421 _output_write();
506 //free_events(_events_list, EINA_TRUE); 422 //free_events(_events_list, EINA_TRUE);