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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/**
* argparser – command line argument parser library
*
* Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org)
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "argparser.h"
/**
* Dummy trigger
*
* @param user_data User-data
* @param used The used option alternative
* @param standard The standard option alternative
*/
void args_noop_trigger(void* user_data, const char* used, const char* standard)
{
(void) user_data;
(void) used;
(void) standard;
}
/**
* Dummy trigger
*
* @param user_data User-data
* @param used The used option alternative
* @param standard The standard option alternative
* @param value The used value
*/
void args_noop_trigger_v(void* user_data, const char* used, const char* standard, char* value)
{
(void) user_data;
(void) used;
(void) standard;
(void) value;
}
/**
* Stickless evaluator to always evaluates to false
*
* @param user_data User-data
* @param argument The next argument
* @return Whether the argument can be used without being sticky
*/
int args_no_stickless(void* user_data, const char* value)
{
(void) user_data;
(void) value;
return 0;
}
/**
* Default stickless evaluator
*
* @param user_data User-data
* @param argument The next argument
* @return Whether the argument can be used without being sticky
*/
int args_default_stickless(void* user_data, const char* argument)
{
(void) user_data;
return (*argument != '-') && (*argument != '+');
}
/**
* Evalutator for end argument of variadic options that always evalutes to false
*
* @param user_data User-data
* @param value The next argument
* @return Whether the argument can be used without being sticky
*/
int args_no_variadic_end(void* user_data, char* value)
{
(void) user_data;
(void) value;
return 0;
}
/**
* The standard abbrevation expander
*
* @param argument The option that not recognised
* @param options All recognised options
* @param count The number of elements in `options`
* @return The only possible expansion, otherwise `null`
*/
const char* args_standard_abbreviations(const char* argument, const char** options, size_t count)
{
const char* rc = null;
size_t i;
for (i = 0; i < count; i++)
{
size_t match = 0;
const char* opt = *(options + i);
while (*(argument + match) && (*(opt + match) == *(argument + match)))
match++;
if (*(argument + match) == 0)
{
if (rc)
return null;
rc = opt;
}
}
return rc;
}
|