-
Notifications
You must be signed in to change notification settings - Fork 1
/
args.h
119 lines (113 loc) · 3.63 KB
/
args.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#pragma once
#include "utils.h"
#include <getopt.h>
#include <string.h>
typedef struct args {
const char *record_in;
const char *record_out;
const char *state_file;
const char *sram_file;
const char *rom_file;
const char *disas_out;
const char *log_file;
bool quiet;
bool just_show_info;
bool no_trace;
bool unlimited_fps;
bool pause_start;
bool start_with_analyzer;
uint64_t verbose_trace_mode;
uint64_t skip_cycles;
uint64_t skip_frames;
} args_t;
static inline int args_parse(args_t *self, int argc, char **argv)
{
const char short_opts[] = "-:f:p:r:c:s:S:d:l:t:iqnua";
const struct option long_opts[] = {
{"skip_frames", required_argument, NULL, 'f'},
{"skip_cycles", required_argument, NULL, 'c'},
{"play_input_record", required_argument, NULL, 'p'},
{"record_input", required_argument, NULL, 'r'},
{"load_state", required_argument, NULL, 's'},
{"sram_file", required_argument, NULL, 'S'},
{"disas_out", required_argument, NULL, 'd'},
{"log_file", required_argument, NULL, 'l'},
{"verbose_trace", required_argument, NULL, 't'},
{"start_with_analyzer", no_argument, NULL, 'a'},
{"no_trace", no_argument, NULL, 'n'},
{"show_info", no_argument, NULL, 'i'},
{"quiet", no_argument, NULL, 'q'},
{"unlimited_fps", no_argument, NULL, 'u'},
{}};
while (optind < argc) {
int c;
if ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
switch (c) {
case 'f':
self->skip_frames = strtoull(optarg, NULL, 10);
if (self->skip_frames == 0) {
self->pause_start = true;
}
break;
case 'c':
self->skip_cycles = strtoull(optarg, NULL, 10);
if (self->skip_cycles == 0) {
self->pause_start = true;
}
break;
case 'p':
GUARD(!self->record_in);
self->record_in = strdup(optarg);
break;
case 'r':
GUARD(!self->record_out);
self->record_out = strdup(optarg);
break;
case 's':
GUARD(!self->sram_file);
self->sram_file = strdup(optarg);
break;
case 'S':
GUARD(!self->state_file);
self->state_file = strdup(optarg);
break;
case 'q':
self->quiet = !self->quiet;
break;
case 'u':
self->unlimited_fps = !self->unlimited_fps;
break;
case 'n':
self->no_trace = !self->no_trace;
break;
case 'a':
self->start_with_analyzer = true;
break;
case 't':
self->verbose_trace_mode = strtoull(optarg, NULL, 10);
break;
case 'd':
GUARD(!self->disas_out);
self->disas_out = strdup(optarg);
break;
case 'l':
GUARD(!self->log_file);
self->log_file = strdup(optarg);
break;
case 'i':
self->just_show_info = true;
break;
case 1:
GUARD(!self->rom_file);
self->rom_file = strdup(optarg);
break;
default:
DIE("unknown arg %c", c);
}
} else {
}
}
return SUCCESS;
error:
return NG;
}