diff options
author | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2020-03-27 15:08:46 +0100 |
---|---|---|
committer | Stefan Schmidt <s.schmidt@samsung.com> | 2020-03-31 14:56:31 +0200 |
commit | 09a7ebdc62db01661a71bd6983c98f12ff4a22da (patch) | |
tree | c229ee06acc0af8f5dee6980bf1531754cd64895 /src/bin/exactness | |
parent | 8ee3ecff9564445fc2ef31e616a37c391b464fe6 (diff) | |
download | efl-09a7ebdc62db01661a71bd6983c98f12ff4a22da.tar.gz |
exactness_player: refactor main method
this refactors everything that is not argc argv related out of the main
method. For later usage
Reviewed-by: Stefan Schmidt <stefan@datenfreihafen.org>
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Differential Revision: https://phab.enlightenment.org/D11614
Diffstat (limited to 'src/bin/exactness')
-rw-r--r-- | src/bin/exactness/player.c | 243 |
1 files changed, 145 insertions, 98 deletions
diff --git a/src/bin/exactness/player.c b/src/bin/exactness/player.c index ea3c88f29a..d351c64aca 100644 --- a/src/bin/exactness/player.c +++ b/src/bin/exactness/player.c @@ -903,65 +903,9 @@ static const Ecore_Getopt optdesc = { } }; -int main(int argc, char **argv) +static Eina_Bool +_setup_dest_type(const char *dest, Eina_Bool external_injection) { - int pret = 1, opt_args = 0; - char *src = NULL, *dest = NULL, *eq; - char *fonts_dir = NULL; - const char *chosen_fonts = NULL; - Eina_Bool show_on_screen = EINA_FALSE; - Eina_Bool want_quit = EINA_FALSE, external_injection = EINA_FALSE; - _evas_new = NULL; - - Ecore_Getopt_Value values[] = { - ECORE_GETOPT_VALUE_STR(dest), - ECORE_GETOPT_VALUE_STR(src), - ECORE_GETOPT_VALUE_BOOL(show_on_screen), - ECORE_GETOPT_VALUE_BOOL(_scan_objects), - ECORE_GETOPT_VALUE_BOOL(external_injection), - ECORE_GETOPT_VALUE_BOOL(_disable_shots), - ECORE_GETOPT_VALUE_STR(fonts_dir), - ECORE_GETOPT_VALUE_BOOL(_stabilize_shots), - ECORE_GETOPT_VALUE_DOUBLE(_speed), - ECORE_GETOPT_VALUE_INT(_verbose), - - ECORE_GETOPT_VALUE_BOOL(want_quit), - ECORE_GETOPT_VALUE_BOOL(want_quit), - ECORE_GETOPT_VALUE_BOOL(want_quit), - ECORE_GETOPT_VALUE_BOOL(want_quit), - ECORE_GETOPT_VALUE_NONE - }; - - _log_domain = eina_log_domain_register("exactness_player", NULL); - - if (!ecore_evas_init()) - return EXIT_FAILURE; - - opt_args = ecore_getopt_parse(&optdesc, values, argc, argv); - if (opt_args < 0) - { - fprintf(stderr, "Failed parsing arguments.\n"); - goto end; - } - if (want_quit) goto end; - - /* Check for a sentinel */ - if (argv[opt_args] && !strcmp(argv[opt_args], "--")) opt_args++; - - /* Check for env variables */ - do - { - eq = argv[opt_args] ? strchr(argv[opt_args], '=') : NULL; - if (eq) - { - char *var = malloc(eq - argv[opt_args] + 1); - memcpy(var, argv[opt_args], eq - argv[opt_args]); - var[eq - argv[opt_args]] = '\0'; - setenv(var, eq + 1, 1); - opt_args++; - } - } while (eq); - if (dest) { _dest = eina_stringshare_add(dest); @@ -975,7 +919,7 @@ int main(int argc, char **argv) if (!ecore_file_mkpath(dest)) { fprintf(stderr, "Path for %s cannot be created\n", dest); - goto end; + return EINA_FALSE; } } else @@ -984,25 +928,21 @@ int main(int argc, char **argv) if (!ecore_file_mkpath(_dest)) { fprintf(stderr, "Directory %s cannot be created\n", _dest); - goto end; + return EINA_FALSE; } } } - if (!src && !external_injection) - { - fprintf(stderr, "no test file specified\n"); - goto end; - } - if (src && external_injection) - { - fprintf(stderr, "Cannot inject events from a source file and from outside simultaneously\n"); - goto end; - } if (external_injection) { _src_type = FTYPE_REMOTE; if (_dest_type == FTYPE_UNKNOWN) _dest_type = FTYPE_REMOTE; } + return EINA_TRUE; +} + +static void +_setup_names(const char *src) +{ if (src) { _src_filename = eina_stringshare_add(src); @@ -1021,25 +961,26 @@ int main(int argc, char **argv) char *dot = strrchr(_test_name, '.'); if (dot) *dot = '\0'; } +} - if (_scan_objects && _dest_type != FTYPE_EXU) - { - fprintf(stderr, "Scan objects options is available only if the destination is a EXU file\n"); - goto end; - } - +static void +_setup_dest_unit(void) +{ if (_dest_type == FTYPE_EXU) _dest_unit = calloc(1, sizeof(*_dest_unit)); +} + +static void +_remove_old_shots(void) +{ if (_dest_type == FTYPE_DIR && _test_name) eina_file_dir_list(_dest, 0, _old_shots_rm_cb, (void *)_test_name); +} - if (!_src_open()) - { - fprintf(stderr, "Unable to read source file\n"); - goto end; - } - - if (!show_on_screen) setenv("ELM_ENGINE", "buffer", 1); +static Eina_Bool +_setup_font_settings(const char *fonts_dir) +{ + const char *chosen_fonts = NULL; if (_src_unit && _src_unit->fonts_path) { char buf[PATH_MAX]; @@ -1049,7 +990,7 @@ int main(int argc, char **argv) { fprintf(stderr, "Unable to use the fonts path '%s' provided in %s\n", _src_unit->fonts_path, _src_filename); - goto end; + return EINA_FALSE; } chosen_fonts = _src_unit->fonts_path; } @@ -1059,7 +1000,7 @@ int main(int argc, char **argv) if (!ecore_file_exists(fonts_dir)) { fprintf(stderr, "Unable to find fonts directory %s\n", fonts_dir); - goto end; + return EINA_FALSE; } if (!chosen_fonts) { @@ -1082,6 +1023,123 @@ int main(int argc, char **argv) setenv("FONTCONFIG_FILE", fonts_conf_name, 1); } } + return EINA_TRUE; +} + +static void +_setup_ee_creation(void) +{ + ecore_evas_callback_new_set(_my_evas_new); + if (_src_type != FTYPE_REMOTE) + ecore_idler_add(_src_feed, NULL); +} + +static void +_write_unit_file(void) +{ + if (_dest && _dest_unit) + { + if (_src_unit) + { + Exactness_Unit *tmp = NULL; + if (_src_type == FTYPE_EXU) tmp = exactness_unit_file_read(_src_filename); + _dest_unit->actions = tmp->actions; + } + exactness_unit_file_write(_dest_unit, _dest); + } +} + +int main(int argc, char **argv) +{ + int pret = 1, opt_args = 0; + char *src = NULL, *dest = NULL, *eq; + char *fonts_dir = NULL; + Eina_Bool show_on_screen = EINA_FALSE; + Eina_Bool want_quit = EINA_FALSE, external_injection = EINA_FALSE; + _evas_new = NULL; + + Ecore_Getopt_Value values[] = { + ECORE_GETOPT_VALUE_STR(dest), + ECORE_GETOPT_VALUE_STR(src), + ECORE_GETOPT_VALUE_BOOL(show_on_screen), + ECORE_GETOPT_VALUE_BOOL(_scan_objects), + ECORE_GETOPT_VALUE_BOOL(external_injection), + ECORE_GETOPT_VALUE_BOOL(_disable_shots), + ECORE_GETOPT_VALUE_STR(fonts_dir), + ECORE_GETOPT_VALUE_BOOL(_stabilize_shots), + ECORE_GETOPT_VALUE_DOUBLE(_speed), + ECORE_GETOPT_VALUE_INT(_verbose), + + ECORE_GETOPT_VALUE_BOOL(want_quit), + ECORE_GETOPT_VALUE_BOOL(want_quit), + ECORE_GETOPT_VALUE_BOOL(want_quit), + ECORE_GETOPT_VALUE_BOOL(want_quit), + ECORE_GETOPT_VALUE_NONE + }; + + _log_domain = eina_log_domain_register("exactness_player", NULL); + + if (!ecore_evas_init()) + return EXIT_FAILURE; + + opt_args = ecore_getopt_parse(&optdesc, values, argc, argv); + if (opt_args < 0) + { + fprintf(stderr, "Failed parsing arguments.\n"); + goto end; + } + if (want_quit) goto end; + + /* Check for a sentinel */ + if (argv[opt_args] && !strcmp(argv[opt_args], "--")) opt_args++; + + /* Check for env variables */ + do + { + eq = argv[opt_args] ? strchr(argv[opt_args], '=') : NULL; + if (eq) + { + char *var = malloc(eq - argv[opt_args] + 1); + memcpy(var, argv[opt_args], eq - argv[opt_args]); + var[eq - argv[opt_args]] = '\0'; + setenv(var, eq + 1, 1); + opt_args++; + } + } while (eq); + + if (!src && !external_injection) + { + fprintf(stderr, "no test file specified\n"); + goto end; + } + if (src && external_injection) + { + fprintf(stderr, "Cannot inject events from a source file and from outside simultaneously\n"); + goto end; + } + if (!_setup_dest_type(dest, external_injection)) + goto end; + + _setup_names(src); + + if (_scan_objects && _dest_type != FTYPE_EXU) + { + fprintf(stderr, "Scan objects options is available only if the destination is a EXU file\n"); + goto end; + } + + _setup_dest_unit(); + _remove_old_shots(); + + if (!_src_open()) + { + fprintf(stderr, "Unable to read source file\n"); + goto end; + } + + if (!show_on_screen) setenv("ELM_ENGINE", "buffer", 1); + if (!_setup_font_settings(fonts_dir)) + goto end; char **new_argv = argv; int new_argc = argc; @@ -1105,22 +1163,11 @@ int main(int argc, char **argv) fprintf(stderr, "no program specified\nUse -h for more information\n"); goto end; } + _setup_ee_creation(); - ecore_evas_callback_new_set(_my_evas_new); - if (_src_type != FTYPE_REMOTE) - ecore_idler_add(_src_feed, NULL); pret = ex_prg_invoke(ex_prg_full_path_guess(new_argv[0]), new_argc, new_argv, EINA_TRUE); - if (_dest && _dest_unit) - { - if (_src_unit) - { - Exactness_Unit *tmp = NULL; - if (_src_type == FTYPE_EXU) tmp = exactness_unit_file_read(_src_filename); - _dest_unit->actions = tmp->actions; - } - exactness_unit_file_write(_dest_unit, _dest); - } + _write_unit_file(); end: ecore_evas_shutdown(); |