summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2020-03-27 15:08:46 +0100
committerStefan Schmidt <s.schmidt@samsung.com>2020-03-31 14:56:31 +0200
commit09a7ebdc62db01661a71bd6983c98f12ff4a22da (patch)
treec229ee06acc0af8f5dee6980bf1531754cd64895
parent8ee3ecff9564445fc2ef31e616a37c391b464fe6 (diff)
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
-rw-r--r--src/bin/exactness/player.c243
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 = {
903 } 903 }
904}; 904};
905 905
906int main(int argc, char **argv) 906static Eina_Bool
907_setup_dest_type(const char *dest, Eina_Bool external_injection)
907{ 908{
908 int pret = 1, opt_args = 0;
909 char *src = NULL, *dest = NULL, *eq;
910 char *fonts_dir = NULL;
911 const char *chosen_fonts = NULL;
912 Eina_Bool show_on_screen = EINA_FALSE;
913 Eina_Bool want_quit = EINA_FALSE, external_injection = EINA_FALSE;
914 _evas_new = NULL;
915
916 Ecore_Getopt_Value values[] = {
917 ECORE_GETOPT_VALUE_STR(dest),
918 ECORE_GETOPT_VALUE_STR(src),
919 ECORE_GETOPT_VALUE_BOOL(show_on_screen),
920 ECORE_GETOPT_VALUE_BOOL(_scan_objects),
921 ECORE_GETOPT_VALUE_BOOL(external_injection),
922 ECORE_GETOPT_VALUE_BOOL(_disable_shots),
923 ECORE_GETOPT_VALUE_STR(fonts_dir),
924 ECORE_GETOPT_VALUE_BOOL(_stabilize_shots),
925 ECORE_GETOPT_VALUE_DOUBLE(_speed),
926 ECORE_GETOPT_VALUE_INT(_verbose),
927
928 ECORE_GETOPT_VALUE_BOOL(want_quit),
929 ECORE_GETOPT_VALUE_BOOL(want_quit),
930 ECORE_GETOPT_VALUE_BOOL(want_quit),
931 ECORE_GETOPT_VALUE_BOOL(want_quit),
932 ECORE_GETOPT_VALUE_NONE
933 };
934
935 _log_domain = eina_log_domain_register("exactness_player", NULL);
936
937 if (!ecore_evas_init())
938 return EXIT_FAILURE;
939
940 opt_args = ecore_getopt_parse(&optdesc, values, argc, argv);
941 if (opt_args < 0)
942 {
943 fprintf(stderr, "Failed parsing arguments.\n");
944 goto end;
945 }
946 if (want_quit) goto end;
947
948 /* Check for a sentinel */
949 if (argv[opt_args] && !strcmp(argv[opt_args], "--")) opt_args++;
950
951 /* Check for env variables */
952 do
953 {
954 eq = argv[opt_args] ? strchr(argv[opt_args], '=') : NULL;
955 if (eq)
956 {
957 char *var = malloc(eq - argv[opt_args] + 1);
958 memcpy(var, argv[opt_args], eq - argv[opt_args]);
959 var[eq - argv[opt_args]] = '\0';
960 setenv(var, eq + 1, 1);
961 opt_args++;
962 }
963 } while (eq);
964
965 if (dest) 909 if (dest)
966 { 910 {
967 _dest = eina_stringshare_add(dest); 911 _dest = eina_stringshare_add(dest);
@@ -975,7 +919,7 @@ int main(int argc, char **argv)
975 if (!ecore_file_mkpath(dest)) 919 if (!ecore_file_mkpath(dest))
976 { 920 {
977 fprintf(stderr, "Path for %s cannot be created\n", dest); 921 fprintf(stderr, "Path for %s cannot be created\n", dest);
978 goto end; 922 return EINA_FALSE;
979 } 923 }
980 } 924 }
981 else 925 else
@@ -984,25 +928,21 @@ int main(int argc, char **argv)
984 if (!ecore_file_mkpath(_dest)) 928 if (!ecore_file_mkpath(_dest))
985 { 929 {
986 fprintf(stderr, "Directory %s cannot be created\n", _dest); 930 fprintf(stderr, "Directory %s cannot be created\n", _dest);
987 goto end; 931 return EINA_FALSE;
988 } 932 }
989 } 933 }
990 } 934 }
991 if (!src && !external_injection)
992 {
993 fprintf(stderr, "no test file specified\n");
994 goto end;
995 }
996 if (src && external_injection)
997 {
998 fprintf(stderr, "Cannot inject events from a source file and from outside simultaneously\n");
999 goto end;
1000 }
1001 if (external_injection) 935 if (external_injection)
1002 { 936 {
1003 _src_type = FTYPE_REMOTE; 937 _src_type = FTYPE_REMOTE;
1004 if (_dest_type == FTYPE_UNKNOWN) _dest_type = FTYPE_REMOTE; 938 if (_dest_type == FTYPE_UNKNOWN) _dest_type = FTYPE_REMOTE;
1005 } 939 }
940 return EINA_TRUE;
941}
942
943static void
944_setup_names(const char *src)
945{
1006 if (src) 946 if (src)
1007 { 947 {
1008 _src_filename = eina_stringshare_add(src); 948 _src_filename = eina_stringshare_add(src);
@@ -1021,25 +961,26 @@ int main(int argc, char **argv)
1021 char *dot = strrchr(_test_name, '.'); 961 char *dot = strrchr(_test_name, '.');
1022 if (dot) *dot = '\0'; 962 if (dot) *dot = '\0';
1023 } 963 }
964}
1024 965
1025 if (_scan_objects && _dest_type != FTYPE_EXU) 966static void
1026 { 967_setup_dest_unit(void)
1027 fprintf(stderr, "Scan objects options is available only if the destination is a EXU file\n"); 968{
1028 goto end;
1029 }
1030
1031 if (_dest_type == FTYPE_EXU) _dest_unit = calloc(1, sizeof(*_dest_unit)); 969 if (_dest_type == FTYPE_EXU) _dest_unit = calloc(1, sizeof(*_dest_unit));
1032 970
971}
972
973static void
974_remove_old_shots(void)
975{
1033 if (_dest_type == FTYPE_DIR && _test_name) 976 if (_dest_type == FTYPE_DIR && _test_name)
1034 eina_file_dir_list(_dest, 0, _old_shots_rm_cb, (void *)_test_name); 977 eina_file_dir_list(_dest, 0, _old_shots_rm_cb, (void *)_test_name);
978}
1035 979
1036 if (!_src_open()) 980static Eina_Bool
1037 { 981_setup_font_settings(const char *fonts_dir)
1038 fprintf(stderr, "Unable to read source file\n"); 982{
1039 goto end; 983 const char *chosen_fonts = NULL;
1040 }
1041
1042 if (!show_on_screen) setenv("ELM_ENGINE", "buffer", 1);
1043 if (_src_unit && _src_unit->fonts_path) 984 if (_src_unit && _src_unit->fonts_path)
1044 { 985 {
1045 char buf[PATH_MAX]; 986 char buf[PATH_MAX];
@@ -1049,7 +990,7 @@ int main(int argc, char **argv)
1049 { 990 {
1050 fprintf(stderr, "Unable to use the fonts path '%s' provided in %s\n", 991 fprintf(stderr, "Unable to use the fonts path '%s' provided in %s\n",
1051 _src_unit->fonts_path, _src_filename); 992 _src_unit->fonts_path, _src_filename);
1052 goto end; 993 return EINA_FALSE;
1053 } 994 }
1054 chosen_fonts = _src_unit->fonts_path; 995 chosen_fonts = _src_unit->fonts_path;
1055 } 996 }
@@ -1059,7 +1000,7 @@ int main(int argc, char **argv)
1059 if (!ecore_file_exists(fonts_dir)) 1000 if (!ecore_file_exists(fonts_dir))
1060 { 1001 {
1061 fprintf(stderr, "Unable to find fonts directory %s\n", fonts_dir); 1002 fprintf(stderr, "Unable to find fonts directory %s\n", fonts_dir);
1062 goto end; 1003 return EINA_FALSE;
1063 } 1004 }
1064 if (!chosen_fonts) 1005 if (!chosen_fonts)
1065 { 1006 {
@@ -1082,6 +1023,123 @@ int main(int argc, char **argv)
1082 setenv("FONTCONFIG_FILE", fonts_conf_name, 1); 1023 setenv("FONTCONFIG_FILE", fonts_conf_name, 1);
1083 } 1024 }
1084 } 1025 }
1026 return EINA_TRUE;
1027}
1028
1029static void
1030_setup_ee_creation(void)
1031{
1032 ecore_evas_callback_new_set(_my_evas_new);
1033 if (_src_type != FTYPE_REMOTE)
1034 ecore_idler_add(_src_feed, NULL);
1035}
1036
1037static void
1038_write_unit_file(void)
1039{
1040 if (_dest && _dest_unit)
1041 {
1042 if (_src_unit)
1043 {
1044 Exactness_Unit *tmp = NULL;
1045 if (_src_type == FTYPE_EXU) tmp = exactness_unit_file_read(_src_filename);
1046 _dest_unit->actions = tmp->actions;
1047 }
1048 exactness_unit_file_write(_dest_unit, _dest);
1049 }
1050}
1051
1052int main(int argc, char **argv)
1053{
1054 int pret = 1, opt_args = 0;
1055 char *src = NULL, *dest = NULL, *eq;
1056 char *fonts_dir = NULL;
1057 Eina_Bool show_on_screen = EINA_FALSE;
1058 Eina_Bool want_quit = EINA_FALSE, external_injection = EINA_FALSE;
1059 _evas_new = NULL;
1060
1061 Ecore_Getopt_Value values[] = {
1062 ECORE_GETOPT_VALUE_STR(dest),
1063 ECORE_GETOPT_VALUE_STR(src),
1064 ECORE_GETOPT_VALUE_BOOL(show_on_screen),
1065 ECORE_GETOPT_VALUE_BOOL(_scan_objects),
1066 ECORE_GETOPT_VALUE_BOOL(external_injection),
1067 ECORE_GETOPT_VALUE_BOOL(_disable_shots),
1068 ECORE_GETOPT_VALUE_STR(fonts_dir),
1069 ECORE_GETOPT_VALUE_BOOL(_stabilize_shots),
1070 ECORE_GETOPT_VALUE_DOUBLE(_speed),
1071 ECORE_GETOPT_VALUE_INT(_verbose),
1072
1073 ECORE_GETOPT_VALUE_BOOL(want_quit),
1074 ECORE_GETOPT_VALUE_BOOL(want_quit),
1075 ECORE_GETOPT_VALUE_BOOL(want_quit),
1076 ECORE_GETOPT_VALUE_BOOL(want_quit),
1077 ECORE_GETOPT_VALUE_NONE
1078 };
1079
1080 _log_domain = eina_log_domain_register("exactness_player", NULL);
1081
1082 if (!ecore_evas_init())
1083 return EXIT_FAILURE;
1084
1085 opt_args = ecore_getopt_parse(&optdesc, values, argc, argv);
1086 if (opt_args < 0)
1087 {
1088 fprintf(stderr, "Failed parsing arguments.\n");
1089 goto end;
1090 }
1091 if (want_quit) goto end;
1092
1093 /* Check for a sentinel */
1094 if (argv[opt_args] && !strcmp(argv[opt_args], "--")) opt_args++;
1095
1096 /* Check for env variables */
1097 do
1098 {
1099 eq = argv[opt_args] ? strchr(argv[opt_args], '=') : NULL;
1100 if (eq)
1101 {
1102 char *var = malloc(eq - argv[opt_args] + 1);
1103 memcpy(var, argv[opt_args], eq - argv[opt_args]);
1104 var[eq - argv[opt_args]] = '\0';
1105 setenv(var, eq + 1, 1);
1106 opt_args++;
1107 }
1108 } while (eq);
1109
1110 if (!src && !external_injection)
1111 {
1112 fprintf(stderr, "no test file specified\n");
1113 goto end;
1114 }
1115 if (src && external_injection)
1116 {
1117 fprintf(stderr, "Cannot inject events from a source file and from outside simultaneously\n");
1118 goto end;
1119 }
1120 if (!_setup_dest_type(dest, external_injection))
1121 goto end;
1122
1123 _setup_names(src);
1124
1125 if (_scan_objects && _dest_type != FTYPE_EXU)
1126 {
1127 fprintf(stderr, "Scan objects options is available only if the destination is a EXU file\n");
1128 goto end;
1129 }
1130
1131 _setup_dest_unit();
1132 _remove_old_shots();
1133
1134 if (!_src_open())
1135 {
1136 fprintf(stderr, "Unable to read source file\n");
1137 goto end;
1138 }
1139
1140 if (!show_on_screen) setenv("ELM_ENGINE", "buffer", 1);
1141 if (!_setup_font_settings(fonts_dir))
1142 goto end;
1085 char **new_argv = argv; 1143 char **new_argv = argv;
1086 int new_argc = argc; 1144 int new_argc = argc;
1087 1145
@@ -1105,22 +1163,11 @@ int main(int argc, char **argv)
1105 fprintf(stderr, "no program specified\nUse -h for more information\n"); 1163 fprintf(stderr, "no program specified\nUse -h for more information\n");
1106 goto end; 1164 goto end;
1107 } 1165 }
1166 _setup_ee_creation();
1108 1167
1109 ecore_evas_callback_new_set(_my_evas_new);
1110 if (_src_type != FTYPE_REMOTE)
1111 ecore_idler_add(_src_feed, NULL);
1112 pret = ex_prg_invoke(ex_prg_full_path_guess(new_argv[0]), new_argc, new_argv, EINA_TRUE); 1168 pret = ex_prg_invoke(ex_prg_full_path_guess(new_argv[0]), new_argc, new_argv, EINA_TRUE);
1113 1169
1114 if (_dest && _dest_unit) 1170 _write_unit_file();
1115 {
1116 if (_src_unit)
1117 {
1118 Exactness_Unit *tmp = NULL;
1119 if (_src_type == FTYPE_EXU) tmp = exactness_unit_file_read(_src_filename);
1120 _dest_unit->actions = tmp->actions;
1121 }
1122 exactness_unit_file_write(_dest_unit, _dest);
1123 }
1124 1171
1125end: 1172end:
1126 ecore_evas_shutdown(); 1173 ecore_evas_shutdown();