Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

cfg+.h

Go to the documentation of this file.
00001 /*
00002  * libcfg+ - precise command line & config file parsing library
00003  *
00004  * cfg+.h - main implementation header file
00005  * ____________________________________________________________
00006  *
00007  * Developed by Ondrej Jombik <nepto@pobox.sk>
00008  * Copyright (c) 2001-2002 Platon SDG, http://www.platon.sk/
00009  * All rights reserved.
00010  *
00011  * See README file for more information about this software.
00012  * See COPYING file for license information.
00013  *
00014  * Download the latest version from
00015  * http://www.platon.sk/projects/libcfg+/
00016  */
00017 
00018 /* $Id: cfg+.h,v 1.36 2002/05/20 16:06:09 jombik9 Exp $ */
00019 
00028 #ifndef _PLATON_CFG_H
00029 #define _PLATON_CFG_H
00030 
00031 #include <stdio.h>
00032 #include "props.h"
00033 
00035 #define CFG_END_OPTION { NULL, '\0', NULL, CFG_END, NULL, 0 }
00036 #define CFG_END_OF_LIST CFG_END_OPTION 
00045 enum cfg_error {
00046 
00049         CFG_ERR_OK = 0,
00050         CFG_ERROR_OK = 0,
00051         CFG_OK = 0,
00055         CFG_ERR_NOARG = -1,
00056         CFG_ERROR_NOARG = -1,
00057 
00059         CFG_ERR_NOTALLOWEDARG = -2,
00060         CFG_ERROR_NOTALLOWEDARG = -2,
00061 
00063         CFG_ERR_BADOPT = -3,
00064         CFG_ERROR_BADOPT = -3,
00065 
00067         CFG_ERR_BADQUOTE = -4,
00068         CFG_ERROR_BADQUOTE = -4,
00069 
00071         CFG_ERR_BADNUMBER = -5,
00072         CFG_ERROR_BADNUMBER = -5,
00073 
00075         CFG_ERR_OVERFLOW = -6,
00076         CFG_ERROR_OVERFLOW = -6,
00077 
00079         CFG_ERR_MULTI = -7,
00080         CFG_ERROR_MULTI = -7,
00081 
00083         CFG_ERR_NOMEM = -8,
00084         CFG_ERROR_NOMEM = -8,
00085 
00087         CFG_ERR_STOP_STR = -9,
00088         CFG_ERR_STOP_STR_FOUND = -9,
00089         CFG_ERROR_STOP_STR = -9,
00090         CFG_ERROR_STOP_STR_FOUND = -9,
00091 
00093         CFG_ERR_NOEQUAL = -10,
00094         CFG_ERROR_NOEQUAL = -10,
00095 
00097         CFG_ERR_UNKNOWN = -11,
00098         CFG_ERROR_UNKNOWN = -11,
00099 
00101         CFG_ERR_FILE_NOT_FOUND = -12,
00102         CFG_ERROR_FILE_NOT_FOUND = -12,
00103 
00105         CFG_ERR_SEEK_ERROR = -13,
00106         CFG_ERROR_SEEK_ERROR = -13,
00107 
00109         CFG_ERR_INTERNAL = -20,
00110         CFG_ERROR_INTERNAL = -20
00111 
00112 };
00124 enum cfg_flag {
00125 
00127         CFG_IGNORE_MULTI = 1,
00128 
00130         CFG_IGNORE_UNKNOWN = 2,
00131 
00133         CFG_SKIP_FIRST = 0,
00134 
00136         CFG_PROCESS_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                 /* Ignore all quotations in options arguments. */
00157                 /*
00158                    CFG_USE_QUOTE = 0,
00159                    CFG_IGNORE_QUOTE = 16
00160                    */
00161                 /* Advanced quotations are things like  option = va"'l'"ue
00162                    which resolves to                                    va'l'ue.
00163 
00164                    We really want this strange stuff? Any volunter?
00165 
00166                    CFG_ADVANCED_QUOTE = 32 + 16
00167                    */
00168 
00169 };
00181 enum cfg_option_type {
00182 
00184         CFG_BOOL = 1,
00185         CFG_BOOLEAN = 1,
00186 
00188         CFG_INT = 2,
00189         CFG_INTEGER = 2,
00190 
00192         CFG_UINT = 3,
00193         CFG_UNSIGNED = 3,
00194         CFG_UNSIGNED_INT = 3,
00195 
00197         CFG_LONG = 4,
00198 
00200         CFG_ULONG = 5,
00201         CFG_UNSIGNED_LONG = 5,
00202 
00204         CFG_FLOAT = 6,
00205 
00207         CFG_DOUBLE = 7,
00208 
00210         CFG_STR = 8,
00211         CFG_STRING = 8,
00212 
00214         CFG_END = 0,
00215 
00217         CFG_DATA_TYPE_MASK = 31,
00218 
00224         CFG_SINGLE = 0,
00225         CFG_MULTI = 32,
00226         CFG_MULTI_ARRAY = 32,
00227         CFG_MULTI_SEPARATED = 32 + 64,
00228 
00233         CFG_LAST_ARGS = 128,
00234         CFG_LAST_ARGUMENTS = 128,
00235         CFG_LEFTOVER_ARGS = 128,
00236         CFG_LEFTOVER_ARGUMENTS = 128
00237 
00238 };
00250 enum cfg_context_type {
00251 
00253         CFG_NO_CONTEXT = 0,
00254 
00256         CFG_CMDLINE = 1,
00257         CFG_LINE = 1,
00258 
00260         CFG_CFGFILE = 2,
00261         CFG_FILE = 2
00262 };
00263 
00269 enum cfg_line_option_type {
00270 
00272         CFG_NONE_OPTION = 0,
00273 
00275         CFG_SHORT_OPTION = 1,
00276 
00278         CFG_LONG_OPTION = 2,
00279 
00281         CFG_SHORT_OPTIONS = 4,
00282 
00284         CFG_LONG_SEPINIT = 8,
00285 
00287         CFG_LONG_NOSEPINIT = 0
00288 };
00294 struct cfg_option {
00296         const char *cmdline_long_name;
00298         const char  cmdline_short_name;
00300         const char *cfgfile_name;
00301 
00304         const enum cfg_option_type type;
00305 
00307         void *value;
00308 
00310         int val;
00311 };
00312 
00316 struct cfg_context {
00317 
00322 
00324         enum cfg_context_type type;
00325 
00327         int flags;
00328 
00330         const struct cfg_option *options;
00331 
00333         enum cfg_error error_code;
00334 
00336         char **quote_prefix;
00337         char **quote_postfix;
00338 
00345 
00346         int argc;
00347         char **argv;
00348 
00349         int cur_idx;
00350         int cur_idx_tmp;
00351         int *used_opt_idx;
00352 
00353         int cur_opt_type;
00354         char *cur_opt;
00355         char *cur_arg;
00356 
00358         char **line_stop_str;
00359 
00361         char **short_option_prefix;
00363         char **long_option_prefix;
00365         char **line_option_arg_separator;
00366 
00368         char **line_multi_vals_separator;
00369 
00376 
00377         long begin_pos;
00378         long end_pos;
00379         char *filename;
00380 
00381         FILE *fhandle;
00382 
00386         char **file_stop_prefix;
00387 
00391         char **comment_prefix;
00392 
00394         char **multi_line_postfix;
00395 
00398         char **file_option_arg_separator;
00399 
00401         char **file_multi_vals_separator;
00402 
00404 };
00405 
00409 typedef struct cfg_context * CFG_CONTEXT;
00410 
00411 /*
00412  * Functions
00413  */
00414 
00415 #ifdef __cplusplus
00416 extern "C" {
00417 #endif
00418 
00423 
00431         CFG_CONTEXT cfg_get_context(struct cfg_option *options);
00432 
00441         CFG_CONTEXT cfg_get_cmdline_context(
00442                         int argc,
00443                         char **argv,
00444                         struct cfg_option *options);
00445 
00455         CFG_CONTEXT cfg_get_cfgfile_context(
00456                         long begin_pos,
00457                         long end_pos,
00458                         char *filename,
00459                         struct cfg_option *options);
00460 
00469         void cfg_set_cmdline_context(
00470                         const CFG_CONTEXT con,
00471                         int argc,
00472                         char **argv);
00473 
00483         void cfg_set_cfgfile_context(
00484                         const CFG_CONTEXT con,
00485                         long begin_pos,
00486                         long end_pos,
00487                         char *filename);
00488 
00495         void cfg_reset_context(const CFG_CONTEXT con);
00496 
00503         void cfg_free_context(const CFG_CONTEXT con);
00504 
00511 
00519         void cfg_set_context_flag(const CFG_CONTEXT con, int flag);
00520 
00528         void cfg_clear_context_flag(const CFG_CONTEXT con, int flag);
00529 
00537         int cfg_get_context_flag(const CFG_CONTEXT con, int flag);
00538 
00539 #define cfg_is_context_flag(con, flag) cfg_get_context_flag(con, flag)
00540 
00548         void cfg_set_context_flags(const CFG_CONTEXT con, int flags);
00549 
00556         int cfg_get_context_flags(const CFG_CONTEXT con);
00557 
00564 
00565         void cfg_clear_multi_vals_separator(const CFG_CONTEXT con);
00566         int cfg_add_multi_vals_separator(const CFG_CONTEXT con, char *str);
00567         int cfg_remove_multi_vals_separator(const CFG_CONTEXT con, char *str);
00568 
00569         void cfg_clear_option_arg_separator(const CFG_CONTEXT con);
00570         int cfg_add_option_arg_separator(const CFG_CONTEXT con, char *str);
00571         int cfg_remove_option_arg_separator(const CFG_CONTEXT con, char *str);
00572 
00573         void cfg_clear_quote_strings(const CFG_CONTEXT con);
00574         int cfg_add_quote_strings(const CFG_CONTEXT con,
00575                         char *prefix, char *postfix);
00576         int cfg_remove_quote_strings(const CFG_CONTEXT con,
00577                         char *prefix, char *postfix);
00578 
00579 #define cfg_clear_cmdline_stop_string(con) \
00580         __cfg_clear_strdyn_array(&((con)->line_stop_str))
00581 #define cfg_add_cmdline_stop_string(con, str) \
00582                 __cfg_add_strdyn_array(&((con)->line_stop_str), str)
00583 #define cfg_remove_cmdline_stop_string(con, str) \
00584                 __cfg_remove_strdyn_array(&((con)->line_stop_str), str)
00585 
00586 #define cfg_clear_cfgfile_stop_prefix(con) \
00587                 __cfg_clear_strdyn_array(&((con)->file_stop_prefix))
00588 #define cfg_add_cfgfile_stop_prefix(con, str) \
00589                 __cfg_add_strdyn_array(&((con)->file_stop_prefix), str)
00590 #define cfg_remove_cfgfile_stop_prefix(con, str) \
00591                 __cfg_remove_strdyn_array(&((con)->file_stop_prefix), str)
00592 
00593 #define cfg_clear_cfgfile_comment_prefix(con) \
00594                 __cfg_clear_strdyn_array(&((con)->comment_prefix))
00595 #define cfg_add_cfgfile_comment_prefix(con, str) \
00596                 __cfg_add_strdyn_array(&((con)->comment_prefix), str)
00597 #define cfg_remove_cfgfile_comment_prefix(con, str) \
00598                 __cfg_remove_strdyn_array(&((con)->comment_prefix), str)
00599 
00600 #define cfg_clear_cmdline_short_option_prefix(con) \
00601                 __cfg_clear_strdyn_array(&((con)->short_option_prefix))
00602 #define cfg_add_cmdline_short_option_prefix(con, str) \
00603                 __cfg_add_strdyn_array(&((con)->short_option_prefix), str)
00604 #define cfg_remove_cmdline_short_option_prefix(con, str) \
00605                 __cfg_remove_strdyn_array(&((con)->short_option_prefix), str)
00606 
00607 #define cfg_clear_cmdline_long_option_prefix(con) \
00608                 __cfg_clear_strdyn_array(&((con)->long_option_prefix))
00609 #define cfg_add_cmdline_long_option_prefix(con, str) \
00610                 __cfg_add_strdyn_array(&((con)->long_option_prefix), str)
00611 #define cfg_remove_cmdline_long_option_prefix(con, str) \
00612                 __cfg_remove_strdyn_array(&((con)->long_option_prefix), str)
00613 
00614 #define cfg_clear_cfgfile_multi_line_postfix(con) \
00615                 __cfg_clear_strdyn_array(&((con)->multi_line_postfix))
00616 #define cfg_add_cfgfile_multi_line_postfix(con, str) \
00617                 __cfg_add_strdyn_array(&((con)->multi_line_postfix), str)
00618 #define cfg_remove_cfgfile_multi_line_postfix(con, str) \
00619                 __cfg_remove_strdyn_array(&((con)->multi_line_postfix), str)
00620 
00621 #define cfg_clear_cmdline_multi_vals_separator(con) \
00622                 __cfg_clear_strdyn_array(&((con)->line_multi_vals_separator))
00623 #define cfg_add_cmdline_multi_vals_separator(con, str) \
00624                 __cfg_add_strdyn_array(&((con)->line_multi_vals_separator), str)
00625 #define cfg_remove_cmdline_multi_vals_separator(con, str) \
00626                 __cfg_remove_strdyn_array(&((con)->line_multi_vals_separator), str)
00627 
00628 #define cfg_clear_cfgfile_multi_vals_separator(con) \
00629                 __cfg_clear_strdyn_array(&((con)->file_multi_vals_separator))
00630 #define cfg_add_cfgfile_multi_vals_separator(con, str) \
00631                 __cfg_add_strdyn_array(&((con)->file_multi_vals_separator), str)
00632 #define cfg_remove_cfgfile_multi_vals_separator(con, str) \
00633                 __cfg_remove_strdyn_array(&((con)->file_multi_vals_separator), str)
00634 
00635 #define cfg_clear_cmdline_option_arg_separator(con) \
00636                 __cfg_clear_strdyn_array(&((con)->line_option_arg_separator))
00637 #define cfg_add_cmdline_option_arg_separator(con, str) \
00638                 __cfg_add_strdyn_array(&((con)->line_option_arg_separator), str)
00639 #define cfg_remove_cmdline_option_arg_separator(con, str) \
00640                 __cfg_remove_strdyn_array(&((con)->line_option_arg_separator), str)
00641 
00642 #define cfg_clear_cfgfile_option_arg_separator(con) \
00643                 __cfg_clear_strdyn_array(&((con)->file_option_arg_separator))
00644 #define cfg_add_cfgfile_option_arg_separator(con, str) \
00645                 __cfg_add_strdyn_array(&((con)->file_option_arg_separator), str)
00646 #define cfg_remove_cfgfile_option_arg_separator(con, str) \
00647                 __cfg_remove_strdyn_array(&((con)->file_option_arg_separator), str)
00648 
00655 
00663                 int cfg_parse(const CFG_CONTEXT con);
00664 
00674         int cfg_get_next_opt(const CFG_CONTEXT con);
00675 
00682         char *cfg_get_cur_opt(const CFG_CONTEXT con);
00683 
00690         char *cfg_get_cur_arg(const CFG_CONTEXT con);
00691 
00698         int cfg_get_cur_idx(const CFG_CONTEXT con);
00699 
00707 
00714         void cfg_print_error(const CFG_CONTEXT con);
00715 
00723         void cfg_fprint_error(const CFG_CONTEXT con, FILE *fh);
00724 
00732         char *cfg_get_error_str(const CFG_CONTEXT con);
00733 
00740         char *cfg_get_static_error_str(const int errorcode);
00743 #ifdef __cplusplus
00744 }
00745 #endif
00746 
00747 #endif /* _PLATON_CFG_H */
00748 

Generated on Fri May 24 02:36:12 2002 for libcfg+ by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001