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
|
#include <stdio.h>
#include <stdlib.h>
#include "../arg.h"
//define ip4 127.0.0.1:8080
s_arg_ip src_ip =
{
.port = 8080,
.ip = 0x7f000001,
.result = NULL
};
//?
//frequency range from 88:108
s_arg_range freq_range =
{
.start = 88,
.end = 108,
.step = 100e3,
.result = NULL
};
s_arg_float ratio_float =
{
.val = 0.8,
.result = NULL
};
char *color_list[] = {"RED","GREEN","BLUE"};
s_arg_list color_name_list =
{
.num = 3,
.default_val = "RED",
.vals = color_list,
.result = NULL
};
s_arg_val number_val =
{
.ptr = NULL,
.default_ptr = NULL,
.result = NULL
};
s_arg_flag flag_help =
{
.used = 0,
.result = NULL
};
//cant be const
def_arg cmd_arg[] =
{
ARG_ENTRY("-a",IP, &src_ip,"test ip address argument"),
ARG_ENTRY("-b",RANGE,&freq_range,"test integer range argument"),
ARG_ENTRY("-c",FLOAT,&ratio_float,"test float number"),
ARG_ENTRY("-d",LIST, &color_name_list,"check list of values"),
ARG_ENTRY("-e",VAL, &number_val,"check number values"),
ARG_ENTRY("-f",FILE, NULL,"check file argument"),
ARG_ENTRY("-g",FLAG, &flag_help,"check flag argument"),
{NULL,0,NULL}
};
int main( int argc, char **argv )
{
int i=0;
arg_t *cfg = NULL;
i = 0;
while ( cmd_arg[i].param != NULL )
{
printf("%s - %s\n",cmd_arg[i].param, cmd_arg[i].help);
i++;
}
cfg = arg_load( argc, argv, cmd_arg );
if (cfg->size == 0)
{
printf("No arguments found\n");
//goto exit_error;
}
for (i=0;i<cfg->size;i++)
{
printf("TYPE:%d\n", cfg->arg[i]->type);
}
//arg_print( cfg );
if (flag_help.result != NULL)
{
printf("Help flag\n");
}
arg_free( cfg );
return 0;
exit_error:
arg_free( cfg );
return -1;
}
|