aboutsummaryrefslogtreecommitdiffstats
path: root/arg.h
blob: 7dff3de4406dc89724b0c8a54c5934000a90a882 (plain) (blame)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#ifndef __ARG_H
#define __ARG_H

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#define ARGT_NONE  0 //nothing
#define ARGT_IP    1 //ip addr
#define ARGT_RANGE 2 //range of values
#define ARGT_FLOAT 3 //could be float
#define ARGT_LIST  4 //list of values
#define ARGT_FILE  5 //path to file
#define ARGT_VAL   6 //command line direct val
#define ARGT_FLAG  7 //flag value on/off

#define ARG_ENTRY(P,T,V) {.param=P,.type=ARGT_##T,.def=V,.used=0}

typedef struct def_arg
{
	char *param;   //parametr that comes from shell
	uint32_t type; //type of argument
	void *def;     //define default values, NULL if no default values
	uint8_t used;
} def_arg;

typedef struct argv_t
{
	int type;
	uint8_t *val; // points to arg_{ip|range|..}
} argv_t;


typedef struct arg_t
{
	int size;
	argv_t **arg;
} arg_t;


typedef struct arg_ip
{
	int used; //value is in cmd
	int def; //says if default should be used if no value in cmd
	uint32_t ip;
	uint32_t default_ip;
	uint16_t port;
	uint32_t default_port;
} arg_ip;

typedef struct s_arg_ip
{
	uint32_t ip;
	uint16_t port;
} s_arg_ip;


typedef struct arg_range
{
	int used;
	int def;
	uint32_t start;
	uint32_t default_start;
	uint32_t end;
	uint32_t default_end;
	uint32_t step;
	uint32_t default_step;
} arg_range;

typedef struct s_arg_range
{
	uint32_t start;
	uint32_t end;
	uint32_t step;
} s_arg_range;


typedef struct arg_float
{
	int used;
	int def;
	float val;
	float default_val;
} arg_float;

typedef struct s_arg_float
{
	float val;
} s_arg_float;


typedef struct arg_list
{
	int used;
	int def;
	uint32_t num;
	void **vals;
	char *default_val;
} arg_list;

typedef struct s_arg_list
{
	uint32_t num;
	void *default_val;
	void **vals;
} s_arg_list;


typedef struct arg_file
{
	int used;
	int def;
	char *name;
	char *default_name;
	char *abspath; //dire where to search stuff?
	char *default_abspath;
} arg_file;

typedef struct s_arg_file
{
	char *name;
	char *abspath;
} s_arg_file;


typedef struct arg_val
{
	int used;
	int def;
	char *ptr;
	char *default_ptr;
} arg_val;

typedef struct s_arg_val
{
	char *ptr;
} s_arg_val;

typedef struct arg_flag
{
	int used;
	int flag;
} arg_flag;

//no need as there is no default values
/*
typedef struct s_arg_flag
{
	int flag;
} s_arg_flag;
*/

arg_t*     arg_load( int argc, char **argv, def_arg *argl );
void       arg_free( arg_t *arg );
int        arg_type( arg_t *arg, int num );
argv_t*    arg_get( arg_t *arg, int num );
arg_ip*    arg_c_ip( uint32_t ip, uint16_t port );
arg_range* arg_c_range( uint32_t start, uint32_t end, uint32_t step );
arg_float* arg_c_float( float val );
arg_list*  arg_c_list( uint32_t num, void **vals, void *def );
arg_file*  arg_c_file( char *name );
arg_val*   arg_c_val( char *ptr );
arg_flag*  arg_c_flag();
void       arg_print( arg_t *arg );

#endif