Add emu_args parser

This commit is contained in:
Rodrigo Arias 2023-01-20 15:36:02 +01:00 committed by Rodrigo Arias Mallo
parent fe5f16bb7a
commit b4d5e33d6c
2 changed files with 71 additions and 0 deletions

56
src/emu/emu_args.c Normal file
View File

@ -0,0 +1,56 @@
/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
#define _POSIX_C_SOURCE 2
#include "emu_args.h"
#include "common.h"
#include <unistd.h>
#include <string.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);
}
void
emu_args_init(struct emu_args *args, int argc, char *argv[])
{
memset(args, 0, sizeof(struct emu_args));
int opt;
while ((opt = getopt(argc, argv, "c:l")) != -1) {
switch (opt) {
case 'c':
args->clock_offset_file = optarg;
break;
case 'l':
args->linter_mode = 1;
break;
default: /* '?' */
usage();
}
}
if (optind >= argc) {
err("missing tracedir\n");
usage();
}
args->tracedir = argv[optind];
}

15
src/emu/emu_args.h Normal file
View File

@ -0,0 +1,15 @@
/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
#ifndef EMU_ARGS_H
#define EMU_ARGS_H
struct emu_args {
int linter_mode;
char *clock_offset_file;
char *tracedir;
};
void emu_args_init(struct emu_args *args, int argc, char *argv[]);
#endif /* EMU_ARGS_H */