00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00030 #ifndef _PLATON_CFG_H
00031 #define _PLATON_CFG_H
00032
00033 #include <stdio.h>
00034
00036 #define CFG_END_OPTION { NULL, '\0', NULL, CFG_END, NULL, 0 }
00037 #define CFG_END_OF_LIST CFG_END_OPTION
00046 enum cfg_error {
00047
00050 CFG_ERR_OK = 0,
00051 CFG_ERROR_OK = 0,
00052 CFG_OK = 0,
00056 CFG_ERR_NOARG = -1,
00057 CFG_ERROR_NOARG = -1,
00058
00060 CFG_ERR_NOTALLOWEDARG = -2,
00061 CFG_ERROR_NOTALLOWEDARG = -2,
00062
00064 CFG_ERR_BADOPT = -3,
00065 CFG_ERROR_BADOPT = -3,
00066
00068 CFG_ERR_BADQUOTE = -4,
00069 CFG_ERROR_BADQUOTE = -4,
00070
00072 CFG_ERR_BADNUMBER = -5,
00073 CFG_ERROR_BADNUMBER = -5,
00074
00076 CFG_ERR_OVERFLOW = -6,
00077 CFG_ERROR_OVERFLOW = -6,
00078
00080 CFG_ERR_MULTI = -7,
00081 CFG_ERROR_MULTI = -7,
00082
00084 CFG_ERR_NOMEM = -8,
00085 CFG_ERROR_NOMEM = -8,
00086
00088 CFG_ERR_STOP_STR = -9,
00089 CFG_ERR_STOP_STR_FOUND = -9,
00090 CFG_ERROR_STOP_STR = -9,
00091 CFG_ERROR_STOP_STR_FOUND = -9,
00092
00094 CFG_ERR_NOEQUAL = -10,
00095 CFG_ERROR_NOEQUAL = -10,
00096
00098 CFG_ERR_UNKNOWN = -11,
00099 CFG_ERROR_UNKNOWN = -11,
00100
00102 CFG_ERR_FILE_NOT_FOUND = -12,
00103 CFG_ERROR_FILE_NOT_FOUND = -12,
00104
00106 CFG_ERR_SEEK_ERROR = -13,
00107 CFG_ERROR_SEEK_ERROR = -13,
00108
00110 CFG_ERR_INTERNAL = -20,
00111 CFG_ERROR_INTERNAL = -20
00112
00113 };
00114
00124 enum cfg_flag {
00125
00127 CFG_IGNORE_MULTI = 1,
00128
00130 CFG_IGNORE_UNKNOWN = 2,
00131
00133 CFG_PROCESS_FIRST = 0,
00134
00136 CFG_SKIP_FIRST = 4,
00137
00139 CFG_POSIXLY_LEFTOVERS = 0,
00140
00142 CFG_ADVANCED_LEFTOVERS = 8,
00143
00145 CFG_NORMAL_LEFTOVERS = 0,
00146
00148 CFG_STRICT_LEFTOVERS = 16,
00149
00151 CFG_FILE_BYTE_POS_USAGE = 0,
00152
00154 CFG_FILE_LINE_POS_USAGE = 32
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 };
00170
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 };
00238
00243 enum cfg_property_type {
00244
00249
00252 CFG_LINE_STOP_STRING = 0,
00253
00256 CFG_LINE_SHORT_OPTION_PREFIX = 1,
00257
00260 CFG_LINE_LONG_OPTION_PREFIX = 2,
00261
00264 CFG_LINE_OPTION_ARG_SEPARATOR = 3,
00265
00268 CFG_LINE_NORMAL_MULTI_VALS_SEPARATOR = 4,
00269
00272 CFG_LINE_LEFTOVER_MULTI_VALS_SEPARATOR = 5,
00273
00276 CFG_LINE_QUOTE_PREFIX = 6,
00277 CFG_LINE_QUOTE_POSTFIX = 7,
00278
00281 CFG_FILE_STOP_PREFIX = 8,
00282
00285 CFG_FILE_COMMENT_PREFIX = 9,
00286
00289 CFG_FILE_MULTI_LINE_POSTFIX = 10,
00290
00293 CFG_FILE_OPTION_ARG_SEPARATOR = 11,
00294
00297 CFG_FILE_NORMAL_MULTI_VALS_SEPARATOR = 12,
00298
00301 CFG_FILE_LEFTOVER_MULTI_VALS_SEPARATOR = 13,
00302
00305 CFG_FILE_QUOTE_PREFIX = 14,
00306 CFG_FILE_QUOTE_POSTFIX = 15,
00307
00315 CFG_N_PROPS = 16,
00322
00324 CFG_QUOTE = 50,
00325 CFG_LINE_QUOTE = 51,
00326 CFG_FILE_QUOTE = 52,
00327 CFG_QUOTE_PREFIX = 53,
00328 CFG_QUOTE_POSTFIX = 54,
00329
00331 CFG_MULTI_VALS_SEPARATOR = 55,
00332 CFG_FILE_MULTI_VALS_SEPARATOR = 56,
00333 CFG_LINE_MULTI_VALS_SEPARATOR = 57,
00334 CFG_NORMAL_MULTI_VALS_SEPARATOR = 58,
00335 CFG_LEFTOVER_MULTI_VALS_SEPARATOR = 59,
00336
00338 CFG_OPTION_ARG_SEPARATOR = 60
00340 };
00341
00346 #define CFG_EOT CFG_N_PROPS
00347 #define CFG_END_TYPE CFG_N_PROPS
00348
00360 enum cfg_context_type {
00361
00363 CFG_NO_CONTEXT = 0,
00364
00366 CFG_CMDLINE = 1,
00367 CFG_LINE = 1,
00368
00370 CFG_CFGFILE = 2,
00371 CFG_FILE = 2
00372 };
00373
00379 enum cfg_line_option_type {
00380
00382 CFG_NONE_OPTION = 0,
00383
00385 CFG_SHORT_OPTION = 1,
00386
00388 CFG_LONG_OPTION = 2,
00389
00391 CFG_SHORT_OPTIONS = 4,
00392
00394 CFG_LONG_SEPINIT = 8,
00395
00397 CFG_LONG_NOSEPINIT = 0
00398 };
00399
00403 struct cfg_option {
00405 const char *cmdline_long_name;
00407 const char cmdline_short_name;
00409 const char *cfgfile_name;
00410
00413 const enum cfg_option_type type;
00414
00416 void *value;
00417
00419 int val;
00420 };
00421
00425 struct cfg_context {
00426
00431
00433 enum cfg_context_type type;
00434
00436 int flags;
00437
00439 const struct cfg_option *options;
00440
00442 long begin_pos;
00443
00446 long size;
00447
00449 int *used_opt_idx;
00450
00452 enum cfg_error error_code;
00453
00455 char **prop[CFG_N_PROPS];
00456
00458 long cur_idx;
00459 long cur_idx_tmp;
00460 int cur_opt_type;
00461
00463 char *cur_opt;
00464
00466 char *cur_arg;
00467
00474
00476 int parsing_started:1;
00477
00479 char **argv;
00480
00487
00489 char *filename;
00490
00492 FILE *fhandle;
00493
00495 };
00496
00500 typedef struct cfg_context * CFG_CONTEXT;
00501
00502
00503
00504
00505
00506 #ifdef __cplusplus
00507 extern "C" {
00508 #endif
00509
00513
00514
00522 CFG_CONTEXT cfg_get_context(struct cfg_option *options);
00523
00534 CFG_CONTEXT cfg_get_cmdline_context(
00535 long begin_pos,
00536 long size,
00537 char **argv,
00538 struct cfg_option *options);
00539
00540 #define cfg_get_cmdline_context_pos(begin_pos, end_pos, argv, options) \
00541 cfg_get_cmdline_context( \
00542 begin_pos, \
00543 end_pos - begin_pos + 1, \
00544 argv, \
00545 options)
00546
00555 CFG_CONTEXT cfg_get_cmdline_context_argc(
00556 int argc,
00557 char **argv,
00558 struct cfg_option *options);
00559
00570 CFG_CONTEXT cfg_get_cfgfile_context(
00571 long begin_pos,
00572 long size,
00573 char *filename,
00574 struct cfg_option *options);
00575
00576 #define cfg_get_cfgfile_context_pos(begin_pos, end_pos, argv, options) \
00577 cfg_get_cfgfile_context( \
00578 begin_pos, \
00579 end_pos - begin_pos + 1, \
00580 argv, \
00581 options)
00582
00593 void cfg_set_cmdline_context(
00594 const CFG_CONTEXT con,
00595 long begin_pos,
00596 long size,
00597 char **argv);
00598
00599 #define cfg_set_cmdline_context_pos(con, begin_pos, end_pos, argv) \
00600 cfg_get_cmdline_context( \
00601 con \
00602 begin_pos, \
00603 end_pos - begin_pos + 1, \
00604 argv)
00605
00614 void cfg_set_cmdline_context_argc(
00615 const CFG_CONTEXT con,
00616 int argc,
00617 char **argv);
00618
00629 void cfg_set_cfgfile_context(
00630 const CFG_CONTEXT con,
00631 long begin_pos,
00632 long size,
00633 char *filename);
00634
00635 #define cfg_set_cfgfile_context_pos(con, begin_pos, end_pos, argv) \
00636 cfg_get_cfgfile_context( \
00637 con \
00638 begin_pos, \
00639 end_pos - begin_pos + 1, \
00640 argv)
00641
00648 void cfg_reset_context(const CFG_CONTEXT con);
00649
00656 void cfg_free_context(const CFG_CONTEXT con);
00657
00658
00659
00663
00664
00672 void cfg_set_context_flag(const CFG_CONTEXT con, int flag);
00673
00681 void cfg_clear_context_flag(const CFG_CONTEXT con, int flag);
00682
00690 int cfg_get_context_flag(const CFG_CONTEXT con, int flag);
00691
00692 #define cfg_is_context_flag(con, flag) cfg_get_context_flag(con, flag)
00693
00701 void cfg_set_context_flags(const CFG_CONTEXT con, int flags);
00702
00709 int cfg_get_context_flags(const CFG_CONTEXT con);
00710
00711
00712
00716
00717
00726 int cfg_clear_property(
00727 const CFG_CONTEXT con, enum cfg_property_type type);
00728
00737 int cfg_clear_properties(
00738 const CFG_CONTEXT con, enum cfg_property_type type, ...);
00739
00740
00750 int cfg_add_property(
00751 const CFG_CONTEXT con, enum cfg_property_type type, char *str);
00752
00766 int cfg_add_properties(
00767 const CFG_CONTEXT con, enum cfg_property_type type, char *str, ...);
00768
00782 int cfg_add_properties_str(
00783 const CFG_CONTEXT con, char *str, enum cfg_property_type type, ...);
00784
00798 int cfg_add_properties_type(
00799 const CFG_CONTEXT con, enum cfg_property_type type, char *str, ...);
00800
00810 int cfg_remove_property(
00811 const CFG_CONTEXT con, enum cfg_property_type type, char *str);
00812
00826 int cfg_remove_properties(
00827 const CFG_CONTEXT con, enum cfg_property_type type, char *str, ...);
00828
00842 int cfg_remove_properties_str(
00843 const CFG_CONTEXT con, char *str, enum cfg_property_type type, ...);
00844
00858 int cfg_remove_properties_type(
00859 const CFG_CONTEXT con, enum cfg_property_type type, char *str, ...);
00860
00861
00862
00866
00867
00876 int cfg_parse(const CFG_CONTEXT con);
00877
00887 int cfg_get_next_opt(const CFG_CONTEXT con);
00888
00895 char *cfg_get_cur_opt(const CFG_CONTEXT con);
00896
00903 char *cfg_get_cur_arg(const CFG_CONTEXT con);
00904
00911 int cfg_get_cur_idx(const CFG_CONTEXT con);
00912
00913
00914
00918
00919
00926 void cfg_print_error(const CFG_CONTEXT con);
00927
00935 void cfg_fprint_error(const CFG_CONTEXT con, FILE *fh);
00936
00944 char *cfg_get_error_str(const CFG_CONTEXT con);
00945
00952 char *cfg_get_static_error_str(const int errorcode);
00953
00954
00955
00956 #ifdef __cplusplus
00957 }
00958 #endif
00959
00960 #endif
00961
00962
00963
00964
00965
00966