-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommandline.h
67 lines (47 loc) · 1.27 KB
/
commandline.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
#ifndef COMMANDLINE_H
#define COMMANDLINE_H
// Define to change from its default
#ifndef MAX_COMMAND_ARGS
#define MAX_COMMAND_ARGS 50
#endif
#pragma once
#include <stdlib.h>
struct CommandLineOption{
const char* name;
const char* description;
int minParamCount;
int maxParamCount;
};
struct CommandLineParser{
const char* args[MAX_COMMAND_ARGS];
int argCount;
int flagIndices[MAX_COMMAND_ARGS];
int flagCount;
bool isProgramNamePresent;
char* cmdLineOwnedString;
CommandLineOption* options;
int optionCount;
CommandLineParser(){
argCount = 0;
flagCount = 0;
isProgramNamePresent = true;
cmdLineOwnedString = nullptr;
optionCount = 0;
}
~CommandLineParser(){
free(cmdLineOwnedString);
}
void SetOptions(CommandLineOption* options, int optionCount);
void InternalFlagSetup();
void InitializeFromArgcArgv(int argc, const char** argv);
void InitializeFromStringNoCopy(char* string);
void InitializeFromString(const char* string);
bool IsFlagPresent(const char* flagName);
const char* FlagValue(const char* flagName);
int FlagIntValue(const char* flagName);
//Assumes that are command-line flags start with "-"
//get however many after it don't
int FlagArgCount(const char* flagName);
const char** FlagArgValues(const char* flagName);
};
#endif