forked from enlightenment/efl
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
This commit is contained in:
parent
b5c24af2e1
commit
b84694f518
|
@ -12,3 +12,89 @@ ex_printf(int verbose, const char *fmt, ...)
|
||||||
vprintf(fmt, ap);
|
vprintf(fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ex_prg_invoke(const char *full_path, int argc, char **argv, Eina_Bool player)
|
||||||
|
{
|
||||||
|
Eina_Value *ret__;
|
||||||
|
int real__;
|
||||||
|
|
||||||
|
void (*efl_main)(void *data, const Efl_Event *ev);
|
||||||
|
int (*elm_main)(int argc, char **argv);
|
||||||
|
int (*c_main)(int argc, char **argv);
|
||||||
|
Eina_Module *h = eina_module_new(full_path);
|
||||||
|
if (!h || !eina_module_load(h))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Failed loading %s.\n", full_path);
|
||||||
|
if (h) eina_module_free(h);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
efl_main = eina_module_symbol_get(h, "efl_main");
|
||||||
|
elm_main = eina_module_symbol_get(h, "elm_main");
|
||||||
|
c_main = eina_module_symbol_get(h, "main");
|
||||||
|
_evas_new = eina_module_symbol_get(h, "evas_new");
|
||||||
|
if (!_evas_new)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Failed loading symbol 'evas_new' from %s.\n", full_path);
|
||||||
|
eina_module_free(h);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (efl_main)
|
||||||
|
{
|
||||||
|
elm_init(argc, argv);
|
||||||
|
if (player) elm_theme_overlay_add(NULL, DATA_DIR"/exactness_play.edj");
|
||||||
|
efl_event_callback_add(efl_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS, efl_main, NULL);
|
||||||
|
ret__ = efl_loop_begin(efl_main_loop_get());
|
||||||
|
real__ = efl_loop_exit_code_process(ret__);
|
||||||
|
elm_shutdown();
|
||||||
|
}
|
||||||
|
else if (elm_main)
|
||||||
|
{
|
||||||
|
elm_init(argc, argv);
|
||||||
|
if (player) elm_theme_overlay_add(NULL, DATA_DIR"/exactness_play.edj");
|
||||||
|
real__ = elm_main(argc, argv);
|
||||||
|
elm_shutdown();
|
||||||
|
}
|
||||||
|
else if (c_main)
|
||||||
|
{
|
||||||
|
real__ = c_main(argc, argv);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Failed loading symbol 'efl_main', 'elm_main' or 'main' from %s.\n", full_path);
|
||||||
|
eina_module_free(h);
|
||||||
|
real__ = 1;
|
||||||
|
}
|
||||||
|
return real__;
|
||||||
|
}
|
||||||
|
|
||||||
|
Eina_Stringshare *
|
||||||
|
ex_prg_full_path_guess(const char *prg)
|
||||||
|
{
|
||||||
|
char full_path[PATH_MAX];
|
||||||
|
if (strchr(prg, '/')) return eina_stringshare_add(prg);
|
||||||
|
char *env_path = eina_strdup(getenv("PATH"));
|
||||||
|
Eina_Stringshare *ret = NULL;
|
||||||
|
char *paths = env_path;
|
||||||
|
|
||||||
|
while (paths && *paths && !ret)
|
||||||
|
{
|
||||||
|
char *real_path;
|
||||||
|
char *colon = strchr(paths, ':');
|
||||||
|
if (colon) *colon = '\0';
|
||||||
|
|
||||||
|
sprintf(full_path, "%s/%s", paths, prg);
|
||||||
|
real_path = ecore_file_realpath(full_path);
|
||||||
|
if (*real_path)
|
||||||
|
{
|
||||||
|
ret = eina_stringshare_add(real_path);
|
||||||
|
// check if executable
|
||||||
|
}
|
||||||
|
free(real_path);
|
||||||
|
|
||||||
|
paths += strlen(paths);
|
||||||
|
if (colon) paths++;
|
||||||
|
}
|
||||||
|
free(env_path);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -97,4 +97,8 @@ foo(Eina_Debug_Session *session, int srcid, void *buffer, int size) \
|
||||||
_buf += __len; \
|
_buf += __len; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Evas *(*_evas_new)(void);
|
||||||
|
|
||||||
void ex_printf(int verbose, const char *fmt, ...);
|
void ex_printf(int verbose, const char *fmt, ...);
|
||||||
|
int ex_prg_invoke(const char *full_path, int argc, char **argv, Eina_Bool player);
|
||||||
|
Eina_Stringshare *ex_prg_full_path_guess(const char *prg);
|
||||||
|
|
|
@ -56,7 +56,6 @@ static Exactness_Unit *_src_unit = NULL;
|
||||||
static const char *_test_name = NULL;
|
static const char *_test_name = NULL;
|
||||||
static int _verbose = 0;
|
static int _verbose = 0;
|
||||||
|
|
||||||
static Evas *(*_evas_new)(void) = NULL;
|
|
||||||
static Eina_List *_evas_list = NULL;
|
static Eina_List *_evas_list = NULL;
|
||||||
|
|
||||||
static Eina_List *_cur_event_list = NULL;
|
static Eina_List *_cur_event_list = NULL;
|
||||||
|
@ -804,94 +803,6 @@ _src_open()
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
_prg_invoke(const char *full_path, int argc, char **argv)
|
|
||||||
{
|
|
||||||
Eina_Value *ret__;
|
|
||||||
int real__;
|
|
||||||
|
|
||||||
void (*efl_main)(void *data, const Efl_Event *ev);
|
|
||||||
int (*elm_main)(int argc, char **argv);
|
|
||||||
int (*c_main)(int argc, char **argv);
|
|
||||||
Eina_Module *h = eina_module_new(full_path);
|
|
||||||
if (!h || !eina_module_load(h))
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed loading %s.\n", full_path);
|
|
||||||
if (h) eina_module_free(h);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
efl_main = eina_module_symbol_get(h, "efl_main");
|
|
||||||
elm_main = eina_module_symbol_get(h, "elm_main");
|
|
||||||
c_main = eina_module_symbol_get(h, "main");
|
|
||||||
_evas_new = eina_module_symbol_get(h, "evas_new");
|
|
||||||
if (!_evas_new)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed loading symbol 'evas_new' from %s.\n", full_path);
|
|
||||||
eina_module_free(h);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (efl_main)
|
|
||||||
{
|
|
||||||
elm_init(argc, argv);
|
|
||||||
elm_theme_overlay_add(NULL, DATA_DIR"/exactness_play.edj");
|
|
||||||
efl_event_callback_add(efl_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS, efl_main, NULL);
|
|
||||||
ret__ = efl_loop_begin(efl_main_loop_get());
|
|
||||||
real__ = efl_loop_exit_code_process(ret__);
|
|
||||||
elm_shutdown();
|
|
||||||
}
|
|
||||||
else if (elm_main)
|
|
||||||
{
|
|
||||||
elm_init(argc, argv);
|
|
||||||
elm_theme_overlay_add(NULL, DATA_DIR"/exactness_play.edj");
|
|
||||||
real__ = elm_main(argc, argv);
|
|
||||||
elm_shutdown();
|
|
||||||
}
|
|
||||||
else if (c_main)
|
|
||||||
{
|
|
||||||
real__ = c_main(argc, argv);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed loading symbol 'efl_main', 'elm_main' or 'main' from %s.\n", full_path);
|
|
||||||
eina_module_free(h);
|
|
||||||
real__ = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return real__;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Eina_Stringshare *
|
|
||||||
_prg_full_path_guess(const char *prg)
|
|
||||||
{
|
|
||||||
char full_path[PATH_MAX];
|
|
||||||
if (strchr(prg, '/')) return eina_stringshare_add(prg);
|
|
||||||
char *env_path = eina_strdup(getenv("PATH"));
|
|
||||||
Eina_Stringshare *ret = NULL;
|
|
||||||
char *paths = env_path;
|
|
||||||
|
|
||||||
while (paths && *paths && !ret)
|
|
||||||
{
|
|
||||||
char *real_path;
|
|
||||||
char *colon = strchr(paths, ':');
|
|
||||||
if (colon) *colon = '\0';
|
|
||||||
|
|
||||||
sprintf(full_path, "%s/%s", paths, prg);
|
|
||||||
real_path = ecore_file_realpath(full_path);
|
|
||||||
if (*real_path)
|
|
||||||
{
|
|
||||||
ret = eina_stringshare_add(real_path);
|
|
||||||
// check if executable
|
|
||||||
}
|
|
||||||
free(real_path);
|
|
||||||
|
|
||||||
paths += strlen(paths);
|
|
||||||
if (colon) paths++;
|
|
||||||
}
|
|
||||||
free(env_path);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_mkdir(const char *path, Eina_Bool skip_last)
|
_mkdir(const char *path, Eina_Bool skip_last)
|
||||||
{
|
{
|
||||||
|
@ -1022,6 +933,7 @@ int main(int argc, char **argv)
|
||||||
const char *chosen_fonts = NULL;
|
const char *chosen_fonts = NULL;
|
||||||
Eina_Bool show_on_screen = EINA_FALSE;
|
Eina_Bool show_on_screen = EINA_FALSE;
|
||||||
Eina_Bool want_quit = EINA_FALSE, external_injection = EINA_FALSE;
|
Eina_Bool want_quit = EINA_FALSE, external_injection = EINA_FALSE;
|
||||||
|
_evas_new = NULL;
|
||||||
|
|
||||||
Ecore_Getopt_Value values[] = {
|
Ecore_Getopt_Value values[] = {
|
||||||
ECORE_GETOPT_VALUE_STR(dest),
|
ECORE_GETOPT_VALUE_STR(dest),
|
||||||
|
@ -1255,7 +1167,7 @@ int main(int argc, char **argv)
|
||||||
ecore_evas_callback_new_set(_my_evas_new);
|
ecore_evas_callback_new_set(_my_evas_new);
|
||||||
if (_src_type != FTYPE_REMOTE)
|
if (_src_type != FTYPE_REMOTE)
|
||||||
ecore_idler_add(_src_feed, NULL);
|
ecore_idler_add(_src_feed, NULL);
|
||||||
pret = _prg_invoke(_prg_full_path_guess(argv[0]), argc - opt_args, argv);
|
pret = ex_prg_invoke(ex_prg_full_path_guess(argv[0]), argc - opt_args, argv, EINA_TRUE);
|
||||||
|
|
||||||
if (_dest && _dest_unit)
|
if (_dest && _dest_unit)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#define SHOT_KEY_STR "F2"
|
#define SHOT_KEY_STR "F2"
|
||||||
#define SAVE_KEY_STR "F3"
|
#define SAVE_KEY_STR "F3"
|
||||||
|
|
||||||
static Evas *(*_evas_new)(void) = NULL;
|
|
||||||
static const char *_out_filename = NULL;
|
static const char *_out_filename = NULL;
|
||||||
static const char *_test_name = NULL;
|
static const char *_test_name = NULL;
|
||||||
static int _verbose = 0;
|
static int _verbose = 0;
|
||||||
|
@ -236,90 +235,6 @@ _my_evas_new(int w EINA_UNUSED, int h EINA_UNUSED)
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
_prg_invoke(const char *full_path, int argc, char **argv)
|
|
||||||
{
|
|
||||||
Eina_Value *ret__;
|
|
||||||
int real__;
|
|
||||||
|
|
||||||
void (*efl_main)(void *data, const Efl_Event *ev);
|
|
||||||
int (*elm_main)(int argc, char **argv);
|
|
||||||
int (*c_main)(int argc, char **argv);
|
|
||||||
Eina_Module *h = eina_module_new(full_path);
|
|
||||||
if (!h || !eina_module_load(h))
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed loading %s.\n", full_path);
|
|
||||||
if (h) eina_module_free(h);
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
efl_main = eina_module_symbol_get(h, "efl_main");
|
|
||||||
elm_main = eina_module_symbol_get(h, "elm_main");
|
|
||||||
c_main = eina_module_symbol_get(h, "main");
|
|
||||||
_evas_new = eina_module_symbol_get(h, "evas_new");
|
|
||||||
if (!_evas_new)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed loading symbol 'evas_new' from %s.\n", full_path);
|
|
||||||
eina_module_free(h);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (efl_main)
|
|
||||||
{
|
|
||||||
elm_init(argc, argv);
|
|
||||||
efl_event_callback_add(efl_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS, efl_main, NULL);
|
|
||||||
ret__ = efl_loop_begin(efl_main_loop_get());
|
|
||||||
real__ = efl_loop_exit_code_process(ret__);
|
|
||||||
elm_shutdown();
|
|
||||||
}
|
|
||||||
else if (elm_main)
|
|
||||||
{
|
|
||||||
elm_init(argc, argv);
|
|
||||||
real__ = elm_main(argc, argv);
|
|
||||||
elm_shutdown();
|
|
||||||
}
|
|
||||||
else if (c_main)
|
|
||||||
{
|
|
||||||
real__ = c_main(argc, argv);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed loading symbol 'efl_main', 'elm_main' or 'main' from %s.\n", full_path);
|
|
||||||
eina_module_free(h);
|
|
||||||
real__ = 1;
|
|
||||||
}
|
|
||||||
return real__;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Eina_Stringshare *
|
|
||||||
_prg_full_path_guess(const char *prg)
|
|
||||||
{
|
|
||||||
char full_path[PATH_MAX];
|
|
||||||
if (strchr(prg, '/')) return eina_stringshare_add(prg);
|
|
||||||
char *env_path = eina_strdup(getenv("PATH"));
|
|
||||||
Eina_Stringshare *ret = NULL;
|
|
||||||
char *paths = env_path;
|
|
||||||
|
|
||||||
while (paths && *paths && !ret)
|
|
||||||
{
|
|
||||||
char *real_path;
|
|
||||||
char *colon = strchr(paths, ':');
|
|
||||||
if (colon) *colon = '\0';
|
|
||||||
|
|
||||||
sprintf(full_path, "%s/%s", paths, prg);
|
|
||||||
real_path = ecore_file_realpath(full_path);
|
|
||||||
if (*real_path)
|
|
||||||
{
|
|
||||||
ret = eina_stringshare_add(real_path);
|
|
||||||
// check if executable
|
|
||||||
}
|
|
||||||
free(real_path);
|
|
||||||
|
|
||||||
paths += strlen(paths);
|
|
||||||
if (colon) paths++;
|
|
||||||
}
|
|
||||||
free(env_path);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_mkdir(const char *dir)
|
_mkdir(const char *dir)
|
||||||
{
|
{
|
||||||
|
@ -370,6 +285,7 @@ int main(int argc, char **argv)
|
||||||
char *fonts_dir = NULL;
|
char *fonts_dir = NULL;
|
||||||
int pret = 1, opt_args = 0;
|
int pret = 1, opt_args = 0;
|
||||||
Eina_Bool want_quit = EINA_FALSE;
|
Eina_Bool want_quit = EINA_FALSE;
|
||||||
|
_evas_new = NULL;
|
||||||
|
|
||||||
Ecore_Getopt_Value values[] = {
|
Ecore_Getopt_Value values[] = {
|
||||||
ECORE_GETOPT_VALUE_STR(dest),
|
ECORE_GETOPT_VALUE_STR(dest),
|
||||||
|
@ -500,7 +416,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
ecore_evas_callback_new_set(_my_evas_new);
|
ecore_evas_callback_new_set(_my_evas_new);
|
||||||
_last_timestamp = ecore_time_get() * 1000;
|
_last_timestamp = ecore_time_get() * 1000;
|
||||||
pret = _prg_invoke(_prg_full_path_guess(argv[0]), argc - opt_args, argv);
|
pret = ex_prg_invoke(ex_prg_full_path_guess(argv[0]), argc - opt_args, argv, EINA_FALSE);
|
||||||
|
|
||||||
_output_write();
|
_output_write();
|
||||||
//free_events(_events_list, EINA_TRUE);
|
//free_events(_events_list, EINA_TRUE);
|
||||||
|
|
Loading…
Reference in New Issue