-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcliargs.cpp
More file actions
65 lines (55 loc) · 1.44 KB
/
cliargs.cpp
File metadata and controls
65 lines (55 loc) · 1.44 KB
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
#include "pch.hpp"
#define CLI_DEFAULT_THREADS 6
struct Cli_Args {
const s8* directory = nullptr;
s32 threads = CLI_DEFAULT_THREADS;
bool8 no_recurse = 0;
};
static void PrintOptionsHelp() {
printf("Options help:\n");
printf("\t-nore\t\tDo not recurse into subdirectories\n");
printf("\t-t<num>\t\tSpecify amount of threads (default:%d)\n", CLI_DEFAULT_THREADS);
}
static void PrintUsage(const s8* exe_name, bool32 opts_help = 1) {
printf("%s [-Options] <directory>\n", exe_name);
if (opts_help) {
PrintOptionsHelp();
}
}
static bool32 IsAsciiDigit(s8 c) {
return c >= '0' && c <= '9';
}
static void ParseArgs(Cli_Args* args, s32 argc, s8* argv[]) {
for (s32 i = 1; i < argc; ++i) {
const s8* arg = argv[i];
if (arg[0] == '-') {
const s8* arg1 = arg + 1;
if (arg1[0] == 't' && IsAsciiDigit(arg1[1])) {
s32 threads = atoi(arg1+1);
threads = max(1, min(32, threads));
args->threads = threads;
}
else if (strcmp(arg1, "nore") == 0) {
args->no_recurse = 1;
}
else {
printf("Unrecognized option: %s\n", arg);
PrintOptionsHelp();
exit(1);
}
}
else {
if (args->directory) {
printf("Invalid argument: %s\n", arg);
PrintUsage(argv[0], 0);
exit(1);
}
args->directory = arg;
}
}
if (!args->directory) {
printf("Missing <directory>\n");
PrintUsage(argv[0]);
exit(1);
}
}