options.h
Go to the documentation of this file.
00001 #ifndef H_OPTIONS
00002 #define H_OPTIONS
00003 
00004 #include <stdio.h>
00005 
00006 #ifdef __cplusplus
00007 extern "C" {
00008 #endif
00009 
00010 
00012         /* Sets the banner for the help message. (pointer is kept) */
00013         void options_banner(const char*message);
00014 
00015         struct option;
00016         struct option_alternative;
00017 
00018         struct option* options_allocate(int n);
00019 
00020         void options_int    (struct option*, const char* name,  
00021                 int *p,  int def_value, const char*desc);
00022 
00023         void options_double (struct option*, const char* name,  
00024                 double *p, double def_value, const char*desc);
00025 
00026         void options_string (struct option*, const char* name, 
00027                 const char** p,const char*def_balue,const char*desc);
00028 
00029         void options_alternative(struct option*, const char*name, struct option_alternative*alt,
00030                 int*value, const char*desc);
00031 
00033         int options_parse_args(struct option*ops, int argc, const char* argv[]);
00034 
00036         int options_parse_file(struct option*ops, const char*pwd, const char*file);
00037 
00038         void options_print_help(struct option*ops, FILE*where);
00039 
00040 
00043 enum option_type { OPTION_STRING=0, OPTION_INT=1, OPTION_DOUBLE=2, OPTION_ALTERNATIVE=3 };
00044  
00045 #define OPTIONS_NAME_MAXSIZE 32
00046 #define OPTIONS_VALUE_MAXSIZE 256
00047 
00048 
00049 struct option {
00051         const char * name;
00052         const char * desc;
00053 
00055         enum option_type type;
00056         
00070         void * value_pointer;
00071 
00072 
00074         int * set_pointer;
00075         
00077         struct option_alternative * alternative;
00078 };
00079 
00080 struct option_alternative { 
00081         const char *label;
00082         int value;
00083         const char *desc;
00084 }; 
00085 
00086 
00088 struct option * options_find(struct option*ops, const char * name);
00089 
00091 int options_requires_argument(struct option*o);
00092 
00094 void options_set_passed(struct option*o);
00095 
00097 int options_try_pair(struct option*ops, const char*name, const char*value);
00098 
00100 int options_set(struct option*op, const char*value);
00101 
00102 int options_valid(struct option*op);
00103 
00104 void options_dump(struct option * options, FILE*f, int write_desc);
00105 
00106 int options_parse_stream(struct option*ops, const char*pwd, FILE*file);
00107 
00109 char * strdup_(const char *s);
00111 int get_double(double*p, const char*s);
00113 int get_int(int*p, const char*s);
00114 /* Find next empty slot in the array. XXX farlo meglio */
00115 struct option* options_next_empty(struct option*ops);
00116 
00117 
00118 
00119 #ifdef __cplusplus
00120 }
00121 #endif
00122 
00123 
00124 
00125 #endif


csm
Author(s): Andrea Censi
autogenerated on Fri May 17 2019 02:28:33