-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy_args.h
87 lines (82 loc) · 3.05 KB
/
easy_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
#pragma once
#include <stdbool.h>
/*
* Adds an argument to the parsing list.
*
* @param char* argShort
* Short version for the identifier (example: "-d"). NULL value means no checking.
* @param char* argLong
* Long version of the identifier (example: "--debug"). NULL value means no checking.
* @param void* func
* Callback function which will called when one of the identifiers is found.
* Signature must be:
*
* "int name(int argc, char* argv[])".
*
* Arguments:
* int argc => size of argv
* char* argv[] => arguments with argv[0] as identifier
*
* Return: int
* The callback function should return a value less than
* zero when the argument is not in well formated or other
* things gone wrong.
*
* @param unsigned arguments
* Defines how many arguments the identifier wants.
* If there are not enough arguments an error will be printed.
*/
int eargs_addArgument(char* argShort, char* argLong, void* func, unsigned arguments);
/**
* Adds an int argument to the parsing list. The value will be parsed with strtol() with no error checking.
* @param char* argShort
* Short version for the identifier (example: "-d"). NULL value means no checking.
* @param char* argLong
* Long version of the identifier (example: "--debug"). NULL value means no checking.
* @param int* container
* Pointer to the target int.
*/
int eargs_addArgumentInt(char* argShort, char* argLong, int* container);
/**
* Adds an int argument to the parsing list. The value will be parsed with strtoul() with no error checking.
* @param char* argShort
* Short version for the identifier (example: "-d"). NULL value means no checking.
* @param char* argLong
* Long version of the identifier (example: "--debug"). NULL value means no checking.
* @param unsigned* container
* Pointer to the target unsigned int.
*/
int eargs_addArgumentUInt(char* argShort, char* argLong, unsigned* container);
/**
* Adds an int argument to the parsing list. The value will be parsed with strtol() with no error checking.
* @param char* argShort
* Short version for the identifier (example: "-d"). NULL value means no checking.
* @param char* argLong
* Long version of the identifier (example: "--debug"). NULL value means no checking.
* @param bool* container
* Pointer to the target boolean.
*/
int eargs_addArgumentFlag(char* argShort, char* argLong, bool* container);
/*
* This method will parse the argument list and writes all arguments in output
* which are not an identifier or an argument for an identifier.
*
* @param int argc
* Size of argv array.
* @param char** argv
* Array with arguments.
*
* @param char** output
* Array for the output arguments. Array must be initialized and
* have at least enough memory for containing all arguments from
* argv.
* @param void* config
* Pointer of the config struct. This struct is passed to the
* functions argument functions. It must be defined by the user of
* this code
*
* @return int
* Returns the number of strings in the output array.
*
*/
int eargs_parse(int argc, char** argv, char** output, void* config);