Recorder: port args to Ecore GetOpt
This commit is contained in:
parent
a74cc726f0
commit
1497fa7336
|
@ -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,11 +8,16 @@
|
|||
#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_File.h>
|
||||
#include <Ecore_Getopt.h>
|
||||
#include <Ecore_Con.h>
|
||||
#include <Elementary.h>
|
||||
|
||||
|
@ -272,7 +275,7 @@ _my_evas_new(int w EINA_UNUSED, int h EINA_UNUSED)
|
|||
return e;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
static int
|
||||
_prg_invoke(const char *full_path, int argc, char **argv)
|
||||
{
|
||||
Eina_Value *ret__;
|
||||
|
@ -353,17 +356,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"
|
||||
" -t file.rec|exu Name of the filename where to store the test\n"
|
||||
" -v Verbose mode\n"
|
||||
" -h Print this message and exit\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_mkdir(const char *dir)
|
||||
{
|
||||
|
@ -384,46 +376,72 @@ _mkdir(const char *dir)
|
|||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static const Ecore_Getopt optdesc = {
|
||||
"exactness_record",
|
||||
"%prog [options] <-v|-t|-h> command",
|
||||
PACKAGE_VERSION,
|
||||
"(C) 2017 Enlightenment",
|
||||
"BSD",
|
||||
"A scenario recorder for EFL based applications.",
|
||||
1,
|
||||
{
|
||||
ECORE_GETOPT_STORE_STR('t', "test", "Name of the filename where to store the test."),
|
||||
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;
|
||||
char *dest = NULL, *eq;
|
||||
int pret = 1, opt_args = 0;
|
||||
Eina_Bool want_quit = EINA_FALSE;
|
||||
|
||||
Ecore_Getopt_Value values[] = {
|
||||
ECORE_GETOPT_VALUE_STR(dest),
|
||||
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();
|
||||
ecore_init();
|
||||
|
||||
opterr = 0;
|
||||
for (int opt; (opt = getopt(argc, argv, "+vt:h")) != -1;)
|
||||
switch (opt)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 't':
|
||||
{
|
||||
_out_filename = eina_stringshare_add(optarg);
|
||||
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 (!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 (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);
|
||||
_out_filename = eina_stringshare_add(dest);
|
||||
|
||||
if (!_out_filename)
|
||||
{
|
||||
fprintf(stderr, "no test file specified\n");
|
||||
|
@ -448,25 +466,37 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
if (strcmp(_out_filename + strlen(_out_filename) - 4,".exu"))
|
||||
{
|
||||
fprintf(stderr, "A file with a exu extension is required - %s invalid\n", _out_filename);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!argv[opt_args])
|
||||
{
|
||||
fprintf(stderr, "no program specified\nUse -h for more information\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
if (!_shot_key) _shot_key = getenv("TSUITE_SHOT_KEY");
|
||||
if (!_shot_key) _shot_key = getenv("SHOT_KEY");
|
||||
if (!_shot_key) _shot_key = SHOT_KEY_STR;
|
||||
|
||||
if (!_events_list)
|
||||
|
@ -479,7 +509,8 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
ecore_evas_callback_new_set(_my_evas_new);
|
||||
_prg_invoke(_prg_full_path_guess(argv[0]), argc - optind, argv);
|
||||
pret = _prg_invoke(_prg_full_path_guess(argv[0]), argc - opt_args, argv);
|
||||
|
||||
_output_write();
|
||||
free_events(_events_list, EINA_TRUE);
|
||||
_events_list = NULL;
|
||||
|
|
Loading…
Reference in New Issue