Player: port args to Ecore GetOpt

master
Daniel Zaoui 5 years ago
parent a62f3906e7
commit a74cc726f0
  1. 4
      src/bin/exactness.c
  2. 245
      src/bin/player.c

@ -72,9 +72,9 @@ _run_command_prepare(const List_Entry *ent, char *buf)
scn_path
);
if (_mode == RUN_PLAY)
eina_strbuf_append_printf(sbuf, "-o '%s/%s' ", _dest_dir, CURRENT_SUBDIR);
eina_strbuf_append_printf(sbuf, "-o '%s/%s' -- ", _dest_dir, CURRENT_SUBDIR);
if (_mode == RUN_INIT)
eina_strbuf_append_printf(sbuf, "-o '%s/%s' ", _dest_dir, ORIG_SUBDIR);
eina_strbuf_append_printf(sbuf, "-o '%s/%s' -- ", _dest_dir, ORIG_SUBDIR);
eina_strbuf_append(sbuf, ent->command);
strncpy(buf, eina_strbuf_string_get(sbuf), SCHEDULER_CMD_SIZE-1);
eina_strbuf_free(sbuf);

@ -1,6 +1,4 @@
#define _GNU_SOURCE 1
#define EFL_EO_API_SUPPORT
#define EFL_BETA_API_SUPPORT
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
@ -10,10 +8,15 @@
#include <sys/sysinfo.h>
#include <dlfcn.h>
#include "config.h"
#ifndef EFL_EO_API_SUPPORT
#define EFL_EO_API_SUPPORT
#endif
#include <Eina.h>
#include <Eo.h>
#include <Evas.h>
#include <Ecore.h>
#include <Ecore_Getopt.h>
#include <Ecore_File.h>
#include <Ecore_Con.h>
#include <Elementary.h>
@ -33,11 +36,11 @@ typedef enum
} File_Type;
static File_Type _dest_type = FTYPE_UNKNOWN;
static const char *_dest = NULL;
static Eina_Stringshare *_dest = NULL;
static Exactness_Unit *_dest_unit = NULL;
static File_Type _src_type = FTYPE_UNKNOWN;
static const char *_src_filename = NULL;
static Eina_Stringshare *_src_filename = NULL;
static Exactness_Unit *_src_unit = NULL;
static const char *_test_name = NULL;
@ -510,24 +513,6 @@ _prg_full_path_guess(const char *prg)
return ret;
}
static void
_print_usage(const char *progn, FILE *outf)
{
fprintf(outf, "Usage: %s [options] [program]\n", progn);
fprintf(outf, "Options:\n"
" -s Show the application on the screen\n"
" -o shots_dir/output.exu Set the destination for the shots.\n"
" If a .exu is given, the shots are stored in the file.\n"
" Otherwise the given path is considered as a directory\n"
" where shots will be stored.\n"
" If omitted, the output type (exu or dir) is determined\n"
" by the given test extenstion (resp. exu or rec).\n"
" -t file.rec Test to run on the given application\n"
" -v Verbose mode\n"
" -h Print this message and exit\n"
"\n");
}
static Eina_Bool
_mkdir(const char *path, Eina_Bool skip_last)
{
@ -563,102 +548,131 @@ _my_evas_new(int w EINA_UNUSED, int h EINA_UNUSED)
return e;
}
static const Ecore_Getopt optdesc = {
"exactness_play",
"%prog [options] <-s|-o|-v|-t|-h> command",
PACKAGE_VERSION,
"(C) 2017 Enlightenment",
"BSD",
"A scenario player for EFL based applications.",
1,
{
ECORE_GETOPT_STORE_STR('o', "output",
" Set the destination for the shots.\n"
" If a .exu is given, the shots are stored in the file.\n"
" Otherwise the given path is considered as a directory\n"
" where shots will be stored.\n"
" If omitted, the output type (exu or dir) is determined\n"
" by the given test extension (resp. exu or rec)."),
ECORE_GETOPT_STORE_STR('t', "test", "Test to run on the given application"),
ECORE_GETOPT_STORE_TRUE('s', "show-on-screen", "Show on screen."),
ECORE_GETOPT_COUNT('v', "verbose", "Turn verbose messages on."),
ECORE_GETOPT_LICENSE('L', "license"),
ECORE_GETOPT_COPYRIGHT('C', "copyright"),
ECORE_GETOPT_VERSION('V', "version"),
ECORE_GETOPT_HELP('h', "help"),
ECORE_GETOPT_SENTINEL
}
};
int main(int argc, char **argv)
{
int pret = 1;
const char *engine = "buffer";
int pret = 1, opt_args = 0;
char *src = NULL, *dest = NULL, *eq;
Eina_Bool show_on_screen = EINA_FALSE;
Eina_Bool want_quit = EINA_FALSE;
Ecore_Getopt_Value values[] = {
ECORE_GETOPT_VALUE_STR(dest),
ECORE_GETOPT_VALUE_STR(src),
ECORE_GETOPT_VALUE_BOOL(show_on_screen),
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
};
eina_init();
eet_init();
ecore_init();
opterr = 0;
for (int opt; (opt = getopt(argc, argv, "+so:vt:h")) != -1;)
switch (opt)
{
case 0:
break;
case 's':
{
engine = NULL;
break;
}
case 'o':
{
_dest = eina_stringshare_add(optarg);
if (!strcmp(_dest + strlen(_dest) - 4,".exu"))
{
_dest_type = FTYPE_EXU;
if (!_mkdir(_dest, EINA_TRUE))
{
fprintf(stderr, "Path for %s cannot be created\n", _dest);
goto end;
}
}
else
{
_dest_type = FTYPE_DIR;
if (!_mkdir(_dest, EINA_FALSE))
{
fprintf(stderr, "Directory %s cannot be created\n", _dest);
goto end;
}
}
break;
}
case 't':
{
_src_filename = eina_stringshare_add(optarg);
if (!strcmp(_src_filename + strlen(_src_filename) - 4,".exu"))
{
_src_type = FTYPE_EXU;
if (_dest_type == FTYPE_UNKNOWN)
{
_dest_type = FTYPE_EXU;
_dest = "./output.exu";
}
}
else if (!strcmp(_src_filename + strlen(_src_filename) - 4,".rec"))
{
_src_type = FTYPE_REC;
if (_dest_type == FTYPE_UNKNOWN)
{
_dest_type = FTYPE_DIR;
_dest = ".";
}
}
break;
}
case 'v':
{
_verbose++;
break;
}
case 'h':
{
_print_usage(argv[0], stdout);
pret = 0;
goto end;
}
default:
{
_print_usage(argv[0], stderr);
goto end;
}
}
if (engine) setenv("ELM_ENGINE", engine, 1);
if (!argv[optind])
opt_args = ecore_getopt_parse(&optdesc, values, argc, argv);
if (opt_args < 0)
{
fprintf(stderr, "no program specified\nUse -h for more information\n");
fprintf(stderr, "Failed parsing arguments.\n");
goto end;
}
if (!_src_filename)
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);
if (!strcmp(_dest + strlen(_dest) - 4,".exu"))
{
_dest_type = FTYPE_EXU;
if (!_mkdir(_dest, EINA_TRUE))
{
fprintf(stderr, "Path for %s cannot be created\n", _dest);
goto end;
}
}
else
{
_dest_type = FTYPE_DIR;
if (!_mkdir(_dest, EINA_FALSE))
{
fprintf(stderr, "Directory %s cannot be created\n", _dest);
goto end;
}
}
}
if (!src)
{
fprintf(stderr, "no test file specified\n");
goto end;
}
else
{
_src_filename = eina_stringshare_add(src);
if (!strcmp(_src_filename + strlen(_src_filename) - 4,".exu"))
{
_src_type = FTYPE_EXU;
if (_dest_type == FTYPE_UNKNOWN)
{
_dest_type = FTYPE_EXU;
_dest = "./output.exu";
}
}
else if (!strcmp(_src_filename + strlen(_src_filename) - 4,".rec"))
{
_src_type = FTYPE_REC;
if (_dest_type == FTYPE_UNKNOWN)
{
_dest_type = FTYPE_DIR;
_dest = ".";
}
}
char *slash = strrchr(_src_filename, '/');
if (slash) _test_name = strdup(slash + 1);
else _test_name = strdup(_src_filename);
@ -666,32 +680,37 @@ int main(int argc, char **argv)
if (dot) *dot = '\0';
}
if (_dest_type == FTYPE_EXU)
if (show_on_screen) setenv("ELM_ENGINE", "buffer", 1);
if (!argv[opt_args])
{
_dest_unit = calloc(1, sizeof(*_dest_unit));
fprintf(stderr, "no program specified\nUse -h for more information\n");
goto end;
}
if (_dest_type == FTYPE_EXU) _dest_unit = calloc(1, sizeof(*_dest_unit));
efl_object_init();
evas_init();
/* Replace the current command line to hide the Exactness part */
int len = argv[argc - 1] + strlen(argv[argc - 1]) - argv[optind];
memcpy(argv[0], argv[optind], len);
int len = argv[argc - 1] + strlen(argv[argc - 1]) - argv[opt_args];
memcpy(argv[0], argv[opt_args], len);
memset(argv[0] + len, 0, _POSIX_PATH_MAX - len);
for (int i = optind; i < argc; i++)
for (int i = opt_args; i < argc; i++)
{
if (i != optind)
if (i != opt_args)
{
argv[i - optind] = argv[0] + (argv[i] - argv[optind]);
argv[i - opt_args] = argv[0] + (argv[i] - argv[opt_args]);
}
_printf(1, "%s ", argv[i - optind]);
_printf(1, "%s ", argv[i - opt_args]);
}
_printf(1, "\n");
ecore_evas_callback_new_set(_my_evas_new);
pret = _prg_invoke(_prg_full_path_guess(argv[0]), argc - optind, argv);
pret = _prg_invoke(_prg_full_path_guess(argv[0]), argc - opt_args, argv);
if (_dest_unit)
if (_dest && _dest_unit)
{
_dest_unit->events = _src_unit->events;
unit_eet_write(_dest_unit, _dest);

Loading…
Cancel
Save