libsc
1.6.0
|
00001 /* 00002 This file is part of the SC Library. 00003 The SC Library provides support for parallel scientific applications. 00004 00005 Copyright (C) 2010 The University of Texas System 00006 00007 The SC Library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 The SC Library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with the SC Library; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00020 02110-1301, USA. 00021 */ 00022 00023 #ifndef SC_OPTIONS_H 00024 #define SC_OPTIONS_H 00025 00026 #include <sc_containers.h> 00027 00028 SC_EXTERN_C_BEGIN; 00029 00030 typedef enum 00031 { 00032 SC_OPTION_SWITCH, 00033 SC_OPTION_BOOL, 00034 SC_OPTION_INT, 00035 SC_OPTION_SIZE_T, 00036 SC_OPTION_DOUBLE, 00037 SC_OPTION_STRING, 00038 SC_OPTION_INIFILE, 00039 SC_OPTION_CALLBACK 00040 } 00041 sc_option_type_t; 00042 00043 typedef struct 00044 { 00045 sc_option_type_t opt_type; 00046 int opt_char; 00047 const char *opt_name; 00048 void *opt_var; 00049 void (*opt_fn) (void); 00050 int has_arg; 00051 int called; 00052 const char *help_string; 00053 char *string_value; 00054 void *user_data; 00055 } 00056 sc_option_item_t; 00057 00058 typedef struct 00059 { 00060 char program_path[BUFSIZ]; 00061 const char *program_name; 00062 sc_array_t *option_items; 00063 int args_alloced; 00064 int first_arg; 00065 int argc; 00066 char **argv; 00067 sc_array_t *subopt_names; 00068 } 00069 sc_options_t; 00070 00076 typedef int (*sc_options_callback_t) (sc_options_t * opt, 00077 const char *optarg, void *data); 00078 00083 sc_options_t *sc_options_new (const char *program_path); 00084 00088 void sc_options_destroy (sc_options_t * opt); 00089 00099 void sc_options_add_switch (sc_options_t * opt, 00100 int opt_char, 00101 const char *opt_name, 00102 int *variable, 00103 const char *help_string); 00104 00110 void sc_options_add_bool (sc_options_t * opt, 00111 int opt_char, 00112 const char *opt_name, 00113 int *variable, int init_value, 00114 const char *help_string); 00115 00120 void sc_options_add_int (sc_options_t * opt, 00121 int opt_char, 00122 const char *opt_name, 00123 int *variable, int init_value, 00124 const char *help_string); 00125 00132 void sc_options_add_size_t (sc_options_t * opt, 00133 int opt_char, 00134 const char *opt_name, 00135 size_t *variable, size_t init_value, 00136 const char *help_string); 00137 00141 void sc_options_add_double (sc_options_t * opt, 00142 int opt_char, 00143 const char *opt_name, 00144 double *variable, 00145 double init_value, 00146 const char *help_string); 00147 00154 void sc_options_add_string (sc_options_t * opt, 00155 int opt_char, 00156 const char *opt_name, 00157 const char **variable, 00158 const char *init_value, 00159 const char *help_string); 00160 00164 void sc_options_add_inifile (sc_options_t * opt, 00165 int opt_char, 00166 const char *opt_name, 00167 const char *help_string); 00168 00177 void sc_options_add_callback (sc_options_t * opt, 00178 int opt_char, 00179 const char *opt_name, 00180 int has_arg, 00181 sc_options_callback_t fn, 00182 void *data, 00183 const char *help_string); 00184 00195 void sc_options_add_suboptions (sc_options_t * opt, 00196 sc_options_t * subopt, 00197 const char *prefix); 00198 00213 void sc_options_print_usage (int package_id, int log_priority, 00214 sc_options_t * opt, 00215 const char *arg_usage); 00216 00228 void sc_options_print_summary (int package_id, 00229 int log_priority, 00230 sc_options_t * opt); 00231 00242 int sc_options_load (int package_id, int err_priority, 00243 sc_options_t * opt, const char *inifile); 00244 00258 int sc_options_save (int package_id, int err_priority, 00259 sc_options_t * opt, const char *inifile); 00260 00271 int sc_options_parse (int package_id, int err_priority, 00272 sc_options_t * opt, int argc, 00273 char **argv); 00274 00285 int sc_options_load_args (int package_id, int err_priority, 00286 sc_options_t * opt, 00287 const char *inifile); 00288 00289 SC_EXTERN_C_END; 00290 00291 #endif /* !SC_OPTIONS_H */