-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.c
81 lines (69 loc) · 1.9 KB
/
options.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "include/options.h"
#include "include/platform.h"
options_t load_options(int argc, char** argv)
{
options_t options;
options.interpret = false;
options.print_help_requested = false;
options.is_target_platform_32_bits = BOOL_CPU_32_BITS;
options.cell_count = 500;
options.buffer_size = 200;
options.input_file_name = NULL;
options.output_file_name = "out";
options.output_file_type = OUTPUT_EXECUTABLE;
for(int i = 1; i < argc; i++)
{
if(argv[i][0] != '-')
{
options.input_file_name = argv[i];
continue;
}
if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
{
options.print_help_requested = true;
break;
}
if(strcmp(argv[i], "-asm") == 0)
{
options.output_file_type = OUTPUT_ASM_FILE;
continue;
}
if(strcmp(argv[i], "-obj") == 0)
{
options.output_file_type = OUTPUT_OBJ_FILE;
continue;
}
if(strcmp(argv[i], "-int") == 0)
{
options.interpret = true;
continue;
}
if(strcmp(argv[i], "-c") == 0)
{
char* p;
options.cell_count = (optint_t)strtoull(argv[++i], &p, 10);
continue;
}
if(strcmp(argv[i], "-b") == 0)
{
char* p;
options.buffer_size = (optint_t)strtoull(argv[++i], &p, 10);
continue;
}
if(strcmp(argv[i], "-bit32") == 0)
{
options.is_target_platform_32_bits = true;
continue;
}
if(strcmp(argv[i], "-o") == 0)
{
options.output_file_name = argv[++i];
continue;
}
}
return options;
}