-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
executable file
·62 lines (54 loc) · 1.24 KB
/
Copy pathexample.c
File metadata and controls
executable file
·62 lines (54 loc) · 1.24 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 <stdio.h>
#include "plib6.h"
// Arguments
enum {
test_arg_1,
test_arg_2,
test_arg_3,
end_arg
};
int
main (int argc, char *argv[])
{
// Setup argument array
static struct plib_Argument pl[end_arg] = {
[test_arg_1] = {"--test1", "-t1", "test argument 1"},
[test_arg_2] = {"--test2", "-t2", "test argument 2"},
[test_arg_3] = {"--test3", "-t3", "test argument 3"}
};
// Initialize arguments
plib_CreateArgAndForAll(pl)
{
plib_ToggleProperty(plib_Arg, PLIB_ENABLED);
plib_ToggleProperty (plib_Arg, PLIB_TAKESVALUE);
}
// Handle errors
ifnot_plib_Parse (pl)
{
printf ("Options: \n");
plib_HelpMenu (pl);
if (PL_RETURN.code != PL_ARG_NONE)
{
// Print error data
printf( "\nArgument parsing error occured:\n");
printf ("%s (%s)\n", plib_Error, plib_ErrorArgument);
return 1;
}
printf ("No arguments provided.\n");
return 0;
}
// Print all values given:
for (int i = 0; i < end_arg; i++)
{
struct plib_Argument local = pl[i];
for (int j = 0; j < local.idx; j++)
{
printf("%s - %s(%d)\n",
local.flag, // flag name
argv[local.vals[j]], // argument value
local.vals[j]); // value index in argv
}
}
// Exit (no cleanup procedure)
return 0;
}