summaryrefslogtreecommitdiff
path: root/extlibs/arg.h
diff options
context:
space:
mode:
Diffstat (limited to 'extlibs/arg.h')
-rw-r--r--extlibs/arg.h197
1 files changed, 197 insertions, 0 deletions
diff --git a/extlibs/arg.h b/extlibs/arg.h
new file mode 100644
index 0000000..18105dc
--- /dev/null
+++ b/extlibs/arg.h
@@ -0,0 +1,197 @@
+#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,H) {.param=P,.type=ARGT_##T,.def=V,.used=0,.help=H}
+
+/*
+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
+} def_arg;
+
+typedef struct argv_t
+{
+ int type;
+ uint8_t *val; // points to arg_{ip|range|..}
+} argv_t;
+
+
+typedef struct arg_t
+{
+ int size; //number of arguments
+ argv_t **arg; //list of pointers to arguments
+} arg_t;
+
+//ip argument default behaviour structure
+/*
+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;
+} s_arg_ip;
+
+//resulting structure with ip/port values
+typedef struct arg_ip
+{
+ uint32_t ip; //IP4 ip addrers
+ uint16_t port;//port number
+} arg_ip;
+
+//configure range argument behaviour
+/*
+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
+} s_arg_range;
+
+//configuration structure for range argument
+typedef struct arg_range
+{
+ uint32_t start;
+ uint32_t end;
+ uint32_t step;
+} arg_range;
+
+//configuration structure for float argument
+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;
+} s_arg_float;
+
+typedef struct arg_float
+{
+ float val;
+} arg_float;
+
+//configuration structure for list argument
+/*
+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
+} s_arg_list;
+
+typedef struct arg_list
+{
+ uint32_t num;
+ char **vals;
+} arg_list;
+
+/*
+configuration structure to default file argument
+*/
+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
+} s_arg_file;
+
+/*
+resulting structure for file argument
+*/
+typedef struct arg_file
+{
+ char *name;
+ char *abspath;
+} arg_file;
+
+
+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;
+} s_arg_val;
+
+typedef struct arg_val
+{
+ char *ptr;
+} arg_val;
+
+typedef struct s_arg_flag
+{
+ int used;
+ int flag;
+} s_arg_flag;
+
+//no need as there is no default values
+typedef struct arg_flag
+{
+ int flag;
+} 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, 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 \ No newline at end of file