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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
#ifndef __ARG_H
#define __ARG_H
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.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,H) {.param=P,.type=ARGT_##T,.def=V,.used=0,.help=H}
/*
typedef struct argv_t
{
int type;
uint8_t *val; // points to arg_{ip|range|..}
} argv_t;
*/
/*
class CmdArgVar
{
int _type;
uint8_t *val; // points to arg_{ip|range|..}
public:
CmdArgVar();
uint8_t *get();
int type();
};
*/
/*
typedef struct arg_t
{
int used;
int size; //number of arguments
argv_t **arg; //list of pointers to arguments
} arg_t;
*/
/*
class CmdArg
{
int used;
int _size; //number of arguments
CmdArgVar **arg; //list of pointers to arguments
public:
CmdArg();
int isUsed();
int size();
};
*/
//ip argument default behaviour structure
//resulting structure with ip/port values
/*
typedef struct arg_ip
{
int used;
uint32_t ip; //IP4 ip addrers
uint16_t port;//port number
} arg_ip;
*/
class CmdArgIp {
int used;
uint32_t ip; //IP4 ip addrers
uint16_t port;//port number
};
/*
Supported ip addresses:
...1 = 127.0.0.1:[default port]
:80 = [default ip]:80
*/
/*
typedef struct s_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 *result;
} s_arg_ip;
*/
class CmdArgIpConf {
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;
CmdArgIp *result;
};
//configure range argument behaviour
//configuration structure for range argument
/*
typedef struct arg_range
{
int used;
uint32_t start;
uint32_t end;
uint32_t step;
} arg_range;
*/
class CmdArgRange {
int used;
uint32_t start;
uint32_t end;
uint32_t step;
};
/*
number format decimal ones
1k = 1000
1m = 1000k = 1000000
1g = 1000m = 1000000k = 1000000000
10:100 - from 10 till 100 step [default step]
100: - from 100 till [default end] [default step]
:200 - from [default start] till
100:200:1 - from 100 till 200 with step 1
*/
/*
typedef struct s_arg_range
{
int used;
int def; //says if default should be used if no value in cmd
uint32_t start;
uint32_t default_start; //default start value
uint32_t end; //
uint32_t default_end; //default end value
uint32_t step; //
uint32_t default_step; //default step value
arg_range *result;
} s_arg_range;
*/
class CmdArgRangeConf {
int used;
int def; //says if default should be used if no value in cmd
uint32_t start;
uint32_t default_start; //default start value
uint32_t end; //
uint32_t default_end; //default end value
uint32_t step; //
uint32_t default_step; //default step value
CmdArgRange *result;
};
//configuration structure for float argument
/*
typedef struct arg_float
{
int used;
float val;
} arg_float;
*/
class CmdArgFloat
{
int used;
float val;
public:
CmdArgFloat();
int isUsed();
float get();
};
/*
typedef struct s_arg_float
{
int used;
int def; //says if default should be used if no value in cmd
float val;
float default_val;
arg_float *result;
} s_arg_float;
*/
class CmdArgFloatConf {
int used;
int def; //says if default should be used if no value in cmd
float val;
float default_val;
CmdArgFloat *result;
public:
CmdArgFloatConf();
void link(CmdArgFloat *floatArg);
int isUsed();
};
//configuration structure for list argument
/*
typedef struct arg_list
{
int used;
uint32_t num;
char **vals;
} arg_list;
*/
class CmdArgList {
int used;
uint32_t num;
char **vals;
};
/*
list arguments by name
supports
PARAM1|PARAM2|PARAM3
*/
/*
typedef struct s_arg_list
{
int used;
int def; //says if default should be used if no value in cmd
uint32_t num;
char **vals; //list of supported arguments
char *default_val; //points to default arguments in da list
arg_list *result;
} s_arg_list;
*/
class CmdArgListConf {
int used;
int def; //says if default should be used if no value in cmd
uint32_t num;
char **vals; //list of supported arguments
char *default_val; //points to default arguments in da list
CmdArgList *result;
};
/*
configuration structure to default file argument
*/
/*
resulting structure for file argument
*/
/*
typedef struct arg_file
{
int used;
char *name;
char *abspath;
} arg_file;
*/
class CmdArgFile {
int used;
char *name;
char *abspath;
};
/*
typedef struct s_arg_file
{
int used;
int def; //says if default should be used if no value in cmd
char *name; //current filename
char *default_name; //default filename
char *abspath; //dire where to search stuff?
char *default_abspath; //default absoulute file path
arg_file *result;
} s_arg_file;
*/
class CmdArgFileConf {
int used;
int def; //says if default should be used if no value in cmd
char *name; //current filename
char *default_name; //default filename
char *abspath; //dire where to search stuff?
char *default_abspath; //default absoulute file path
CmdArgFile *result;
};
/*
typedef struct arg_val
{
int used;
char *ptr;
} arg_val;
typedef struct s_arg_val
{
int used;
int def; //says if default should be used if no value in cmd
char *ptr;
char *default_ptr;
arg_val *result;
} s_arg_val;
*/
class CmdArgVal {
int used;
char *ptr;
public:
CmdArgVal();
int isUsed();
//char* get(); //do not free
void setUsed();
void setValue(char *val);
void setFlag();
char *getValue();
};
class CmdArgValConf {
int used;
int def; //says if default should be used if no value in cmd
char *ptr;
char *default_ptr;
CmdArgVal *result;
public:
CmdArgValConf();
int isUsed();
void setUsed();
void link(CmdArgVal *valArg);
};
/*
//no need as there is no default values
typedef struct arg_flag
{
int used;
int flag;
} arg_flag;
typedef struct s_arg_flag
{
int used;
int flag; //do we need it?
arg_flag *result;
} s_arg_flag;
*/
class CmdArgFlag {
int used;
int flag;
public:
CmdArgFlag();
int isUsed();
int get();
void setUsed();
void setFlag();
int getValue();
};
class CmdArgFlagConf {
int used;
int flag; //do we need it?
CmdArgFlag *result;
public:
CmdArgFlagConf();
CmdArgFlagConf(int flag);
int isUsed();
void setUsed();
void link(CmdArgFlag *flagArg);
};
/*
used to define table with predefine arguments
*/
/*
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;
char *help; //command description
void *result; //result
} def_arg;
*/
class CmdArgDefault
{
char *param; //parametr that comes from shell
uint32_t type; //type of argument
void *def; //define default values, NULL if no default values
int32_t used;
char *help; //command description
void *result; //result where to save resulting value
public:
CmdArgDefault();
//CmdArgDefault(char *param, uint32_t type, void *def, char *help, void *result);
CmdArgDefault(char *param, CmdArgFlagConf *def, char *help, CmdArgFlag *result);
//CmdArgDefault(char *param, CmdArgFlagConf *def, char *help, CmdArgFlag *result);
CmdArgDefault(char *param, CmdArgValConf *def, char *help, CmdArgVal *result);
void setParam(char *param);
char *getParam();
void setType(uint32_t type);
uint32_t getType();
void setDefValue(void *def);
int isUsed();
void setUsed();
void setHelp(char *help);
void link(void *result);
void *getResult();
void *getDefault();
};
class CmdArg {
int num;
void **defaultArgs;
int searchArg(char *in);
int *usedArgs;
int usedArgsNum;
public:
CmdArg();
void load(int argc, char **argv);
void add(CmdArgDefault *param);
};
/*
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, char **vals);
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
|