00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00028 #ifndef _PLATON_CFG_H
00029 #define _PLATON_CFG_H
00030
00031 #include <stdio.h>
00032
00034 #define CFG_END_OPTION { NULL, '\0', NULL, CFG_END, NULL, 0 }
00035 #define CFG_END_OF_LIST CFG_END_OPTION
00044 enum cfg_error {
00045
00048 CFG_ERR_OK = 0,
00049 CFG_ERROR_OK = 0,
00050 CFG_OK = 0,
00054 CFG_ERR_NOARG = -1,
00055 CFG_ERROR_NOARG = -1,
00056
00058 CFG_ERR_NOTALLOWEDARG = -2,
00059 CFG_ERROR_NOTALLOWEDARG = -2,
00060
00062 CFG_ERR_BADOPT = -3,
00063 CFG_ERROR_BADOPT = -3,
00064
00066 CFG_ERR_BADQUOTE = -4,
00067 CFG_ERROR_BADQUOTE = -4,
00068
00070 CFG_ERR_BADNUMBER = -5,
00071 CFG_ERROR_BADNUMBER = -5,
00072
00074 CFG_ERR_OVERFLOW = -6,
00075 CFG_ERROR_OVERFLOW = -6,
00076
00078 CFG_ERR_MULTI = -7,
00079 CFG_ERROR_MULTI = -7,
00080
00082 CFG_ERR_NOMEM = -8,
00083 CFG_ERROR_NOMEM = -8,
00084
00086 CFG_ERR_STOP_STR = -9,
00087 CFG_ERR_STOP_STR_FOUND = -9,
00088 CFG_ERROR_STOP_STR = -9,
00089 CFG_ERROR_STOP_STR_FOUND = -9,
00090
00092 CFG_ERR_NOEQUAL = -10,
00093 CFG_ERROR_NOEQUAL = -10,
00094
00096 CFG_ERR_UNKNOWN = -11,
00097 CFG_ERROR_UNKNOWN = -11,
00098
00100 CFG_ERR_FILE_NOT_FOUND = -12,
00101 CFG_ERROR_FILE_NOT_FOUND = -12,
00102
00104 CFG_ERR_SEEK_ERROR = -13,
00105 CFG_ERROR_SEEK_ERROR = -13,
00106
00108 CFG_ERR_INTERNAL = -20,
00109 CFG_ERROR_INTERNAL = -20
00110
00111 };
00123 enum cfg_flag {
00124
00126 CFG_IGNORE_MULTI = 1,
00127
00129 CFG_IGNORE_UNKNOWN = 2,
00130
00132 CFG_SKIP_FIRST = 0,
00133
00135 CFG_PROCESS_FIRST = 4,
00136
00138 CFG_POSIXLY_LEFTOVERS = 0,
00139
00141 CFG_ADVANCED_LEFTOVERS = 8,
00142
00144 CFG_NORMAL_LEFTOVERS = 0,
00145
00147 CFG_STRICT_LEFTOVERS = 16,
00148
00150 CFG_FILE_BYTE_POS_USAGE = 0,
00151
00153 CFG_FILE_LINE_POS_USAGE = 32
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 };
00180 enum cfg_option_type {
00181
00183 CFG_BOOL = 1,
00184 CFG_BOOLEAN = 1,
00185
00187 CFG_INT = 2,
00188 CFG_INTEGER = 2,
00189
00191 CFG_UINT = 3,
00192 CFG_UNSIGNED = 3,
00193 CFG_UNSIGNED_INT = 3,
00194
00196 CFG_LONG = 4,
00197
00199 CFG_ULONG = 5,
00200 CFG_UNSIGNED_LONG = 5,
00201
00203 CFG_FLOAT = 6,
00204
00206 CFG_DOUBLE = 7,
00207
00209 CFG_STR = 8,
00210 CFG_STRING = 8,
00211
00213 CFG_END = 0,
00214
00216 CFG_DATA_TYPE_MASK = 31,
00217
00223 CFG_SINGLE = 0,
00224 CFG_MULTI = 32,
00225 CFG_MULTI_ARRAY = 32,
00226 CFG_MULTI_SEPARATED = 32 + 64,
00227
00232 CFG_LAST_ARGS = 128,
00233 CFG_LAST_ARGUMENTS = 128,
00234 CFG_LEFTOVER_ARGS = 128,
00235 CFG_LEFTOVER_ARGUMENTS = 128
00236
00237 };
00244 enum cfg_property_type {
00245
00250
00252 CFG_LINE_STOP_STRING = 0,
00253
00255 CFG_LINE_SHORT_OPTION_PREFIX = 1,
00256
00258 CFG_LINE_LONG_OPTION_PREFIX = 2,
00259
00261 CFG_LINE_OPTION_ARG_SEPARATOR = 3,
00262
00264 CFG_LINE_MULTI_VALS_SEPARATOR = 4,
00265
00267 CFG_QUOTE_PREFIX = 5,
00268 CFG_QUOTE_POSTFIX = 6,
00269
00273 CFG_FILE_STOP_PREFIX = 7,
00274
00278 CFG_FILE_COMMENT_PREFIX = 8,
00279
00281 CFG_FILE_MULTI_LINE_POSTFIX = 9,
00282
00285 CFG_FILE_OPTION_ARG_SEPARATOR = 10,
00286
00288 CFG_FILE_MULTI_VALS_SEPARATOR = 11,
00289
00297 CFG_N_PROPS = 12,
00304
00305 CFG_VIRTUAL_SPECIAL_PROPERTY = 13
00307 };
00319 enum cfg_context_type {
00320
00322 CFG_NO_CONTEXT = 0,
00323
00325 CFG_CMDLINE = 1,
00326 CFG_LINE = 1,
00327
00329 CFG_CFGFILE = 2,
00330 CFG_FILE = 2
00331 };
00332
00338 enum cfg_line_option_type {
00339
00341 CFG_NONE_OPTION = 0,
00342
00344 CFG_SHORT_OPTION = 1,
00345
00347 CFG_LONG_OPTION = 2,
00348
00350 CFG_SHORT_OPTIONS = 4,
00351
00353 CFG_LONG_SEPINIT = 8,
00354
00356 CFG_LONG_NOSEPINIT = 0
00357 };
00363 struct cfg_option {
00365 const char *cmdline_long_name;
00367 const char cmdline_short_name;
00369 const char *cfgfile_name;
00370
00373 const enum cfg_option_type type;
00374
00376 void *value;
00377
00379 int val;
00380 };
00381
00385 struct cfg_context {
00386
00391
00393 enum cfg_context_type type;
00394
00396 int flags;
00397
00399 const struct cfg_option *options;
00400
00402 int *used_opt_idx;
00403
00405 enum cfg_error error_code;
00406
00408 char **prop[CFG_N_PROPS];
00409
00416
00417 int argc;
00418 char **argv;
00419
00420 int cur_idx;
00421 int cur_idx_tmp;
00422 int cur_opt_type;
00423
00424 char *cur_opt;
00425 char *cur_arg;
00426
00433
00434 long begin_pos;
00435 long end_pos;
00436 char *filename;
00437 FILE *fhandle;
00438
00440 };
00441
00445 typedef struct cfg_context * CFG_CONTEXT;
00446
00447
00448
00449
00450
00451 #ifdef __cplusplus
00452 extern "C" {
00453 #endif
00454
00459
00467 CFG_CONTEXT cfg_get_context(struct cfg_option *options);
00468
00477 CFG_CONTEXT cfg_get_cmdline_context(
00478 int argc,
00479 char **argv,
00480 struct cfg_option *options);
00481
00491 CFG_CONTEXT cfg_get_cfgfile_context(
00492 long begin_pos,
00493 long end_pos,
00494 char *filename,
00495 struct cfg_option *options);
00496
00505 void cfg_set_cmdline_context(
00506 const CFG_CONTEXT con,
00507 int argc,
00508 char **argv);
00509
00519 void cfg_set_cfgfile_context(
00520 const CFG_CONTEXT con,
00521 long begin_pos,
00522 long end_pos,
00523 char *filename);
00524
00531 void cfg_reset_context(const CFG_CONTEXT con);
00532
00539 void cfg_free_context(const CFG_CONTEXT con);
00540
00547
00555 void cfg_set_context_flag(const CFG_CONTEXT con, int flag);
00556
00564 void cfg_clear_context_flag(const CFG_CONTEXT con, int flag);
00565
00573 int cfg_get_context_flag(const CFG_CONTEXT con, int flag);
00574
00575 #define cfg_is_context_flag(con, flag) cfg_get_context_flag(con, flag)
00576
00584 void cfg_set_context_flags(const CFG_CONTEXT con, int flags);
00585
00592 int cfg_get_context_flags(const CFG_CONTEXT con);
00593
00600
00609 void cfg_clear_property(
00610 const CFG_CONTEXT con, enum cfg_property_type type);
00611
00621 int cfg_add_property(
00622 const CFG_CONTEXT con, enum cfg_property_type type, char *str);
00623
00633 int cfg_remove_property(
00634 const CFG_CONTEXT con, enum cfg_property_type type, char *str);
00635
00642
00650 int cfg_parse(const CFG_CONTEXT con);
00651
00661 int cfg_get_next_opt(const CFG_CONTEXT con);
00662
00669 char *cfg_get_cur_opt(const CFG_CONTEXT con);
00670
00677 char *cfg_get_cur_arg(const CFG_CONTEXT con);
00678
00685 int cfg_get_cur_idx(const CFG_CONTEXT con);
00686
00694
00701 void cfg_print_error(const CFG_CONTEXT con);
00702
00710 void cfg_fprint_error(const CFG_CONTEXT con, FILE *fh);
00711
00719 char *cfg_get_error_str(const CFG_CONTEXT con);
00720
00727 char *cfg_get_static_error_str(const int errorcode);
00730 #ifdef __cplusplus
00731 }
00732 #endif
00733
00734 #endif
00735