From 183df35459ba77f735e63e04b385a7f71757daf3 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Fri, 20 Jan 2023 15:41:16 +0100 Subject: [PATCH] Use emu_args to parse input arguments --- src/emu/emu.c | 60 +++++++-------------------------------------------- src/emu/emu.h | 5 ++--- 2 files changed, 10 insertions(+), 55 deletions(-) diff --git a/src/emu/emu.c b/src/emu/emu.c index e72fd25..14d1c4e 100644 --- a/src/emu/emu.c +++ b/src/emu/emu.c @@ -7,51 +7,6 @@ #include -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 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[]) { memset(emu, 0, sizeof(*emu)); - parse_args(emu, argc, argv); - /* Load the streams into the emu_trace */ - if (emu_trace_load(&emu->trace, emu->tracedir) != 0) { + emu_args_init(&emu->args, argc, argv); + + /* Load the streams into the trace */ + if (emu_trace_load(&emu->trace, emu->args.tracedir) != 0) { err("emu_init: cannot load trace '%s'\n", - emu->tracedir); + emu->args.tracedir); return -1; } - /* Parse the streams and build the emu_system */ - if (emu_system_load(&emu->system, &emu->trace) != 0) { + /* Parse the trace and build the emu_system */ + if (emu_system_init(&emu->system, &emu->args, &emu->trace) != 0) { err("emu_init: cannot parse trace '%s'\n", - emu->tracedir); + emu->args.tracedir); return -1; } diff --git a/src/emu/emu.h b/src/emu/emu.h index e7dc062..8712946 100644 --- a/src/emu/emu.h +++ b/src/emu/emu.h @@ -7,6 +7,7 @@ #include "bay.h" #include "pvtrace.h" #include "emu_trace.h" +#include "emu_args.h" #include "emu_system.h" enum error_values { @@ -31,10 +32,8 @@ struct model_spec { struct emu { struct bay *bay; struct pvman *pvman; - char *tracedir; - int enable_linter; - char *clock_offset_file; + struct emu_args args; struct emu_trace trace; struct emu_system system;