Loading...
Searching...
No Matches
parser.h
1
4
5// ALLOW FORMATTING
6#ifndef PARSER_H
7#define PARSER_H
8
9#include "stdbool.h"
10
11#define MAX_ARGS 5
12#define MAX_ARG_LEN 20
13#define MAX_VALUE_LEN 50
14#define MAX_GROUPS 5
15
16typedef enum {
17 ARG_TYPE_BOOL,
18 ARG_TYPE_STRING
19} ArgType;
20
21typedef struct {
22 char name[MAX_ARG_LEN]; // Full name (e.g., "--flag")
23 char shorthand; // Shorthand name (e.g., '-f')
24 ArgType type;
25 bool required;
26 bool provided;
27 char value[MAX_VALUE_LEN];
28} Argument;
29
30typedef struct {
31 int count;
32 int indices[MAX_ARGS];
34
35typedef enum {
36 PARSER_STATUS_OK,
37 PARSER_STATUS_ERROR
38} ErrorStatus;
39
40typedef struct {
41 ErrorStatus status;
42 char *msg; // TODO: Make error field fixed string to allow sprintf
43} Error;
44
45// TODO: Implement mutual requirement for arguments that must be present together
46typedef struct ArgParser {
47 bool initialised;
48 Error error;
49 Argument args[MAX_ARGS];
50 int numArgs;
51 ExclusionGroup groups[MAX_GROUPS];
52 int numGroups;
53 int (*addArg)(struct ArgParser *parser, const char *name, char shorthand, ArgType type, bool required);
54 int (*addMutexGroup)(struct ArgParser *parser, int indices[], int count);
55 bool (*parseArgs)(struct ArgParser *parser, int argc, char *argv[]);
56} ArgParser;
57
58ArgParser ArgParser_init();
59int ArgParser_addArg(ArgParser *parser, const char *name, char shorthand, ArgType type, bool required);
60int ArgParser_addMutexGroup(ArgParser *parser, int indices[], int count);
61bool ArgParser_parseArgs(ArgParser *parser, int argc, char *argv[]);
62
63#endif
Definition parser.h:40