Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hack3ric committed Mar 29, 2024
1 parent 5c2f5cf commit dc8a076
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/args.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <argp.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -41,20 +42,19 @@ static inline error_t argp_parse_cmd(struct argp_state* state, const char* cmdna
return result;
}

#define gen_cmd_parse(_cmd) \
if (strcmp(arg, #_cmd) == 0) { \
args->cmd = CMD_##_cmd; \
return argp_parse_cmd(state, #_cmd, &(_cmd##_argp), &args->_cmd); \
}

static inline error_t args_parse_opt(int key, char* arg, struct argp_state* state) {
struct arguments* args = (struct arguments*)state->input;
if (args->cmd != CMD_NULL) return ARGP_ERR_UNKNOWN;

switch (key) {
case ARGP_KEY_ARG:
gen_cmd_parse(run);
gen_cmd_parse(show);
if (strcmp(arg, "run") == 0) {
args->cmd = CMD_RUN;
return argp_parse_cmd(state, "run", &run_argp, &args->run);
} else if (strcmp(arg, "show") == 0) {
args->cmd = CMD_SHOW;
return argp_parse_cmd(state, "show", &show_argp, &args->show);
};
log_error(_("unknown command '%s'"), arg);
exit(1);
break;
Expand Down
4 changes: 2 additions & 2 deletions src/mimic.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ int main(int argc, char** argv) {
try(argp_parse(&argp, argc, argv, ARGP_IN_ORDER, NULL, &args), _("error parsing arguments"));

switch (args.cmd) {
case CMD_run:
case CMD_RUN:
return -subcmd_run(&args.run);
case CMD_show:
case CMD_SHOW:
return -subcmd_show(&args.show);
default:
break;
Expand Down
4 changes: 2 additions & 2 deletions src/mimic.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
struct arguments {
enum {
CMD_NULL,
CMD_run,
CMD_show,
CMD_RUN,
CMD_SHOW,
} cmd;
union {
struct run_arguments {
Expand Down
3 changes: 2 additions & 1 deletion src/shared/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
#define max(x, y) ((x) < (y) ? (y) : (x))
#define cmp(x, y) ((x) > (y) - (x) < (y))

// Some missing declaration of vmlinux.h
#ifdef _MIMIC_BPF

// Some missing declaration of vmlinux.h

#define htons bpf_htons
#define htonl bpf_htonl
#define ntohs bpf_ntohs
Expand Down

0 comments on commit dc8a076

Please sign in to comment.