Use emu_args to parse input arguments

This commit is contained in:
Rodrigo Arias 2023-01-20 15:41:16 +01:00 committed by Rodrigo Arias Mallo
parent 0687197f08
commit 183df35459
2 changed files with 10 additions and 55 deletions

View File

@ -7,51 +7,6 @@
#include <unistd.h> #include <unistd.h>
static char progname[] = "ovniemu";
static void
usage(void)
{
err("Usage: %s [-c offsetfile] tracedir\n", progname);
err("\n");
err("Options:\n");
err(" -c offsetfile Use the given offset file to correct\n");
err(" the clocks among nodes. It can be\n");
err(" generated by the ovnisync program\n");
err("\n");
err(" tracedir The output trace dir generated by ovni.\n");
err("\n");
err("The output PRV files are placed in the tracedir directory.\n");
exit(EXIT_FAILURE);
}
static void
parse_args(struct emu *emu, int argc, char *argv[])
{
int opt;
while ((opt = getopt(argc, argv, "c:l")) != -1) {
switch (opt) {
case 'c':
emu->clock_offset_file = optarg;
break;
case 'l':
emu->enable_linter = 1;
break;
default: /* '?' */
usage();
}
}
if (optind >= argc) {
err("missing tracedir\n");
usage();
}
emu->tracedir = argv[optind];
}
int int
emu_model_register(struct emu *emu, struct model_spec *spec, void *ctx) emu_model_register(struct emu *emu, struct model_spec *spec, void *ctx)
{ {
@ -76,19 +31,20 @@ int
emu_init(struct emu *emu, int argc, char *argv[]) emu_init(struct emu *emu, int argc, char *argv[])
{ {
memset(emu, 0, sizeof(*emu)); memset(emu, 0, sizeof(*emu));
parse_args(emu, argc, argv);
/* Load the streams into the emu_trace */ emu_args_init(&emu->args, argc, argv);
if (emu_trace_load(&emu->trace, emu->tracedir) != 0) {
/* Load the streams into the trace */
if (emu_trace_load(&emu->trace, emu->args.tracedir) != 0) {
err("emu_init: cannot load trace '%s'\n", err("emu_init: cannot load trace '%s'\n",
emu->tracedir); emu->args.tracedir);
return -1; return -1;
} }
/* Parse the streams and build the emu_system */ /* Parse the trace and build the emu_system */
if (emu_system_load(&emu->system, &emu->trace) != 0) { if (emu_system_init(&emu->system, &emu->args, &emu->trace) != 0) {
err("emu_init: cannot parse trace '%s'\n", err("emu_init: cannot parse trace '%s'\n",
emu->tracedir); emu->args.tracedir);
return -1; return -1;
} }

View File

@ -7,6 +7,7 @@
#include "bay.h" #include "bay.h"
#include "pvtrace.h" #include "pvtrace.h"
#include "emu_trace.h" #include "emu_trace.h"
#include "emu_args.h"
#include "emu_system.h" #include "emu_system.h"
enum error_values { enum error_values {
@ -31,10 +32,8 @@ struct model_spec {
struct emu { struct emu {
struct bay *bay; struct bay *bay;
struct pvman *pvman; struct pvman *pvman;
char *tracedir;
int enable_linter;
char *clock_offset_file;
struct emu_args args;
struct emu_trace trace; struct emu_trace trace;
struct emu_system system; struct emu_system system;