cfg+.h   cfg+.h 
/* /*
* libcfg+ - precise command line & config file parsing library * libcfg+ - precise command line & config file parsing library
* *
* cfg+.h - main implementation header file * cfg+.h - main implementation header file
* ____________________________________________________________ * ____________________________________________________________
* *
* Developed by Ondrej Jombik <nepto@pobox.sk> * Developed by Ondrej Jombik <nepto@pobox.sk>
* and Lubomir Host <rajo@host.sk> * and Lubomir Host <rajo@host.sk>
* Copyright (c) 2001-2002 Platon SDG, http://www.platon.sk/ * Copyright (c) 2001-2002 Platon SDG, http://www.platon.sk/
* All rights reserved. * All rights reserved.
* *
* See README file for more information about this software. * See README file for more information about this software.
* See COPYING file for license information. * See COPYING file for license information.
* *
* Download the latest version from * Download the latest version from
* http://www.platon.sk/projects/libcfg+/ * http://www.platon.sk/projects/libcfg+/
*/ */
/* $Id: cfg+.h,v 1.44 2002/07/18 22:16:30 nepto Exp $ */ /* $Platon: libcfg+/src/cfg+.h,v 1.54 2002/10/07 10:54:44 rajo Exp $ */
/** /**
* @file cfg+.h * @file cfg+.h
* @brief main implementation header file * @brief main implementation header file
* @author Ondrej Jombik <nepto@pobox.sk> * @author Ondrej Jombik <nepto@pobox.sk>
* @author Lubomir Host <rajo@host.sk> * @author Lubomir Host <rajo@host.sk>
* @version \$Id: cfg+.h,v 1.44 2002/07/18 22:16:30 nepto Exp $ * @version \$Platon: libcfg+/src/cfg+.h,v 1.54 2002/10/07 10:54:44 rajo Exp $
* @date 2001-2002 * @date 2001-2002
*/ */
#ifndef _PLATON_CFG_H #ifndef _PLATON_CFG_H
#define _PLATON_CFG_H #define _PLATON_CFG_H
#include <stdio.h> #include <stdio.h>
/** End of options list marker */ /** End of options list marker */
#define CFG_END_OPTION { NULL, '\0', NULL, CFG_END, NULL, 0 } #define CFG_END_OPTION { NULL, '\0', NULL, CFG_END, NULL, 0 }
#define CFG_END_OF_LIST CFG_END_OPTION /**< @ref CFG_END_OPTION */ #define CFG_END_OF_LIST CFG_END_OPTION /**< Alias for @ref CFG_END_OPTION * /
/** /**
* @name Error codes * @name Error codes
*/ */
/*@{*/ /*@{*/
/** /**
* Possible return values returned by parsing functions. * Possible return values returned by parsing functions.
*/ */
enum cfg_error { /* {{{ */ enum cfg_error { /* {{{ */
skipping to change at line 113 skipping to change at line 113
CFG_ERROR_FILE_NOT_FOUND = -12, CFG_ERROR_FILE_NOT_FOUND = -12,
/** Seek error (fseek() failure). */ /** Seek error (fseek() failure). */
CFG_ERR_SEEK_ERROR = -13, CFG_ERR_SEEK_ERROR = -13,
CFG_ERROR_SEEK_ERROR = -13, CFG_ERROR_SEEK_ERROR = -13,
/** Internal error. */ /** Internal error. */
CFG_ERR_INTERNAL = -20, CFG_ERR_INTERNAL = -20,
CFG_ERROR_INTERNAL = -20 CFG_ERROR_INTERNAL = -20
}; /* }}} */ }; /* }}} */ /*@}*/
/*@}*/
/** /**
* @name Context flags * @name Context flags
*/ */
/*@{*/ /*@{*/
/** /**
* By default are @ref CFG_PROCESS_FIRST, @ref CFG_POSIXLY_LEFTOVERS and * By default are @ref CFG_PROCESS_FIRST, @ref CFG_POSIXLY_LEFTOVERS and
* @ref CFG_NORMAL_LEFTOVERS initialized. * @ref CFG_NORMAL_LEFTOVERS initialized.
* @todo CFG_APPEND, CFG_OVERWRITE, CFG_APPEND_MULTI_ONLY * @todo CFG_APPEND, CFG_OVERWRITE, CFG_APPEND_MULTI_ONLY
*/ */
skipping to change at line 170 skipping to change at line 169
CFG_IGNORE_QUOTE = 16 CFG_IGNORE_QUOTE = 16
*/ */
/* Advanced quotations are things like option = va"'l'"ue /* Advanced quotations are things like option = va"'l'"ue
which resolves to va'l 'ue. which resolves to va'l 'ue.
We really want this strange stuff? Any volunter? We really want this strange stuff? Any volunter?
CFG_ADVANCED_QUOTE = 32 + 16 CFG_ADVANCED_QUOTE = 32 + 16
*/ */
}; /* }}} */ }; /* }}} */ /*@}*/
/*@}*/
/** /**
* @name Option types * @name Option types
*/ */
/*@{*/ /*@{*/
/** /**
* Possible types of options * Possible types of options
* @todo Thinking about case insensitivy of option * @todo Thinking about case insensitivy of option
* ("--input" is the same as "--INPUT") * ("--input" is the same as "--INPUT")
*/ */
skipping to change at line 239 skipping to change at line 237
/** /**
* Leftover arguments specification. * Leftover arguments specification.
* Mark option which will contain leftover arguments. * Mark option which will contain leftover arguments.
*/ */
CFG_LAST_ARGS = 128, CFG_LAST_ARGS = 128,
CFG_LAST_ARGUMENTS = 128, CFG_LAST_ARGUMENTS = 128,
CFG_LEFTOVER_ARGS = 128, CFG_LEFTOVER_ARGS = 128,
CFG_LEFTOVER_ARGUMENTS = 128 CFG_LEFTOVER_ARGUMENTS = 128
}; /* }}} */ }; /* }}} */ /*@}*/
/*@}*/
/** /**
* @name Special properties types * @name Property types
*/ */
/*@{*/ /*@{*/
enum cfg_property_type { /* {{{ */ enum cfg_property_type { /* {{{ */
/** /**
* @name Special properties codes * @name Property codes
*/ */
/*@{*/ /*@{*/
/** Array of strings which forces to stop command line parsing. */ /** Array of strings which forces to stop command line parsing.
By default it is empty. */
CFG_LINE_STOP_STRING = 0, CFG_LINE_STOP_STRING = 0,
/** Command line short option prefix (default: "-") */ /** Command line short option prefix.
By default is "-" initilized. */
CFG_LINE_SHORT_OPTION_PREFIX = 1, CFG_LINE_SHORT_OPTION_PREFIX = 1,
/** Command line long option prefix (default: "--") */ /** Command line long option prefix.
By default is "--" iitialized. */
CFG_LINE_LONG_OPTION_PREFIX = 2, CFG_LINE_LONG_OPTION_PREFIX = 2,
/** Command line option argument separator (default: "=") */ /** Command line option argument separator.
By default is "=" initialized. */
CFG_LINE_OPTION_ARG_SEPARATOR = 3, CFG_LINE_OPTION_ARG_SEPARATOR = 3,
/** Command line multi values separator. */ /** Command line multi values separator.
By default are "," and ";" initialized. */
CFG_LINE_NORMAL_MULTI_VALS_SEPARATOR = 4, CFG_LINE_NORMAL_MULTI_VALS_SEPARATOR = 4,
/** Command line multi values leftover arguments separator */ /** Command line multi values leftover arguments separator.
By default it is empty. */
CFG_LINE_LEFTOVER_MULTI_VALS_SEPARATOR = 5, CFG_LINE_LEFTOVER_MULTI_VALS_SEPARATOR = 5,
/** Command line quote prefix & postfix */ /** Command line quote prefix & postfix.
CFG_LINE_QUOTE_PREFIX = 6, By default are apostrophes (') and quotations (") initlized for bo
th.*/
CFG_LINE_QUOTE_PREFIX = 6,
CFG_LINE_QUOTE_POSTFIX = 7, CFG_LINE_QUOTE_POSTFIX = 7,
/** Array of strings prefixes which forces to stop config file parsi ng. /** Array of strings prefixes which forces to stop config file parsi ng.
* default: "[" By default it is empty. */
*/
CFG_FILE_STOP_PREFIX = 8, CFG_FILE_STOP_PREFIX = 8,
/** Array of string prefixes which mark comment line. /** Array of string prefixes which mark comment line.
* defaults: "#", ";" By default are "#" and ";" initialized. */
*/
CFG_FILE_COMMENT_PREFIX = 9, CFG_FILE_COMMENT_PREFIX = 9,
/** Array of string postfixes to determine multi lines. */ /** Array of string postfixes to determine multi lines.
By default is "\\" initialized. */
CFG_FILE_MULTI_LINE_POSTFIX = 10, CFG_FILE_MULTI_LINE_POSTFIX = 10,
/** Config file option argument separator (default: "=") */ /** Config file option argument separator.
By default is "=" initialized. */
CFG_FILE_OPTION_ARG_SEPARATOR = 11, CFG_FILE_OPTION_ARG_SEPARATOR = 11,
/** Config file multi values separator. */ /** Config file multi values separator.
By default are ",", ";" and " " initialized. */
CFG_FILE_NORMAL_MULTI_VALS_SEPARATOR = 12, CFG_FILE_NORMAL_MULTI_VALS_SEPARATOR = 12,
/** Command line multi values leftover arguments separator */ /** Command line multi values leftover arguments separator.
By default is " " initialized. */
CFG_FILE_LEFTOVER_MULTI_VALS_SEPARATOR = 13, CFG_FILE_LEFTOVER_MULTI_VALS_SEPARATOR = 13,
/** Config file quote prefix & postfix */ /** Config file quote prefix & postfix.
CFG_FILE_QUOTE_PREFIX = 14, By default are apostrophes (') and quotations (\") initlized for b
oth.*/
CFG_FILE_QUOTE_PREFIX = 14,
CFG_FILE_QUOTE_POSTFIX = 15, CFG_FILE_QUOTE_POSTFIX = 15,
/*@}*/ /*@}*/
/** /**
* @name Numbers of normal properties * @name Count of normal properties
*/ */
/*@{*/ /*@{*/
/** Special properties count */ /** Special properties count */
CFG_N_PROPS = 16, CFG_N_PROPS = 16,
/*@}*/ /*@}*/
/** /**
* @name Virtual properties codes * @name Virtual property codes
*/ */
/*@{*/ /*@{*/
/** File quote prefix & postfix */ /** File quote prefix & postfix */
CFG_QUOTE = 50, CFG_QUOTE = 50,
CFG_LINE_QUOTE = 51, CFG_LINE_QUOTE = 51,
CFG_FILE_QUOTE = 52, CFG_FILE_QUOTE = 52,
CFG_QUOTE_PREFIX = 53, CFG_QUOTE_PREFIX = 53,
CFG_QUOTE_POSTFIX = 54, CFG_QUOTE_POSTFIX = 54,
/** Multi values separator */ /** Multi values separator */
CFG_MULTI_VALS_SEPARATOR = 55, CFG_MULTI_VALS_SEPARATOR = 55,
CFG_FILE_MULTI_VALS_SEPARATOR = 56, CFG_FILE_MULTI_VALS_SEPARATOR = 56,
CFG_LINE_MULTI_VALS_SEPARATOR = 57, CFG_LINE_MULTI_VALS_SEPARATOR = 57,
CFG_NORMAL_MULTI_VALS_SEPARATOR = 58, CFG_NORMAL_MULTI_VALS_SEPARATOR = 58,
CFG_LEFTOVER_MULTI_VALS_SEPARATOR = 59, CFG_LEFTOVER_MULTI_VALS_SEPARATOR = 59,
/** Option argument separator */ /** Option argument separator */
CFG_OPTION_ARG_SEPARATOR = 60, CFG_OPTION_ARG_SEPARATOR = 60
/* TODO: virtual properties */
CFG_VIRTUAL_SPECIAL_PROPERTY = 99
/*@}*/ /*@}*/
}; /* }}} */ }; /* }}} */
/**
* Terminators of variable number arguments in functions cfg_add_properties
(),
* cfg_set_properties(), cfg_get_properties() and similar.
*/
#define CFG_EOT CFG_N_PROPS
#define CFG_END_TYPE CFG_N_PROPS
/*@}*/ /*@}*/
/** /**
* @name Internal enumerations * @name Internal enumerations
*/ */
/*@{*/ /*@{*/
/** /**
* Context type * Context type
* *
* Possible types of context (used internally) * Possible types of context (used internally)
skipping to change at line 386 skipping to change at line 398
CFG_LONG_OPTION = 2, CFG_LONG_OPTION = 2,
/** Short command line options */ /** Short command line options */
CFG_SHORT_OPTIONS = 4, CFG_SHORT_OPTIONS = 4,
/** Long command line option argument initialized with separator */ /** Long command line option argument initialized with separator */
CFG_LONG_SEPINIT = 8, CFG_LONG_SEPINIT = 8,
/** Long command line option argument initialized without separator (default) */ /** Long command line option argument initialized without separator (default) */
CFG_LONG_NOSEPINIT = 0 CFG_LONG_NOSEPINIT = 0
}; /* }}} */ }; /* }}} */ /*@}*/
/*@}*/
/** /**
* @brief Structure for defining one config option * @brief Structure for defining one config option
*/ */
struct cfg_option { /* {{{ */ struct cfg_option { /* {{{ */
/** Command line long name (may be NULL) */ /** Command line long name (may be NULL) */
const char *cmdline_long_name; const char *cmdline_long_name;
/** Command line short name (may be '\0') */ /** Command line short name (may be '\0') */
const char cmdline_short_name; const char cmdline_short_name;
/** Config file name (may be NULL) */ /** Config file name (may be NULL) */
skipping to change at line 502 skipping to change at line 513
* Functions * Functions
*/ */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/** /**
* @name Functions and macros for creating and manipulating context * @name Functions and macros for creating and manipulating context
*/ */
/*@{*/ /*@{*/ /* {{{ */
/* {{{ */
/** /**
* Initialize core context * Initialize core context
* *
* @param options pointer to options table * @param options pointer to options table
* @return initialized core context; further sp ecification * @return initialized core context; further sp ecification
* to command line or config fi le is required * to command line or config fi le is required
*/ */
CFG_CONTEXT cfg_get_context(struct cfg_option *options); CFG_CONTEXT cfg_get_context(struct cfg_option *options);
skipping to change at line 648 skipping to change at line 658
void cfg_reset_context(const CFG_CONTEXT con); void cfg_reset_context(const CFG_CONTEXT con);
/** /**
* Destroy context * Destroy context
* *
* @param con initialized context * @param con initialized context
* @return void * @return void
*/ */
void cfg_free_context(const CFG_CONTEXT con); void cfg_free_context(const CFG_CONTEXT con);
/* }}} */ /* }}} */ /*@}*/
/*@}*/
/** /**
* @name Functions for setting and clearing context flags * @name Functions for setting and clearing context flags
*/ */
/*@{*/ /*@{*/ /* {{{ */
/* {{{ */
/** /**
* Set context flag * Set context flag
* *
* @param con initialized context * @param con initialized context
* @param flag context flag * @param flag context flag
* @return void * @return void
*/ */
void cfg_set_context_flag(const CFG_CONTEXT con, int flag); void cfg_set_context_flag(const CFG_CONTEXT con, int flag);
skipping to change at line 703 skipping to change at line 711
void cfg_set_context_flags(const CFG_CONTEXT con, int flags); void cfg_set_context_flags(const CFG_CONTEXT con, int flags);
/** /**
* Get all context flags * Get all context flags
* *
* @param con initialized context * @param con initialized context
* @return all context flags * @return all context flags
*/ */
int cfg_get_context_flags(const CFG_CONTEXT con); int cfg_get_context_flags(const CFG_CONTEXT con);
/* }}} */ /* }}} */ /*@}*/
/*@}*/
/** /**
* @name Functions and macros for properties manipulation * @name Functions and macros for properties manipulation
*/ */
/*@{*/ /*@{*/ /* {{{ */
/* {{{ */
/** /**
* Clear all strings of property * Clear all strings of property
* *
* @param con initialized context * @param con initialized context
* @param type property type * @param type property type
* @return 1 on success, 0 on not enough memory error * @return 1 on success, 0 on not enough memory error
* @see cfg_property_type * @see cfg_property_type
*/ */
int cfg_clear_property( int cfg_clear_property(
const CFG_CONTEXT con, enum cfg_property_type type); const CFG_CONTEXT con, enum cfg_property_type type);
/** /**
* Clear all strings of property
*
* @param con initialized context
* @param type property type
* @return 1 on success, 0 on not enough memory error
* @see cfg_property_type
*/
int cfg_clear_properties(
const CFG_CONTEXT con, enum cfg_property_type type,
...);
/**
* Add string to property * Add string to property
* *
* @param con initialized context * @param con initialized context
* @param type property type * @param type property type
* @param str string for addition * @param str string for addition
* @return 1 on success, 0 on not enough memory error * @return 1 on success, 0 on not enough memory error
* @see cfg_property_type * @see cfg_property_type
*/ */
int cfg_add_property( int cfg_add_property(
const CFG_CONTEXT con, enum cfg_property_type type, char *str); const CFG_CONTEXT con, enum cfg_property_type type, char *str);
/** /**
* Add multiple strings to particular properties
*
* @param con initialized context
* @param type property type(s)
* @param str string(s) for addition
* @return 1 on success, 0 on not enough memory error
* @see cfg_property_type
*
* Argument list must be terminated with typeN = CFG_EOT or strN = N
ULL.
* Use constructions like this:<br>
* cfg_add_properties(con, type1, str1, type2, str2, type3=CFG_EOT)
*/
int cfg_add_properties(
const CFG_CONTEXT con, enum cfg_property_type type,
char *str, ...);
/**
* Add string to multiple properties
*
* @param con initialized context
* @param str string for addition
* @param type property type(s)
* @return 1 on success, 0 on not enough memory error
* @see cfg_property_type
*
* Argument list must be terminated with typeN = CFG_EOT. Use constr
uctions
* like this:<br>
* cfg_add_properties(con, str, type1, type2, type3=CFG_EOT)
*/
int cfg_add_properties_str(
const CFG_CONTEXT con, char *str, enum cfg_property_
type type, ...);
/**
* Add multiple strings to one property
*
* @param con initialized context
* @param type property type
* @param str string(s) for addition
* @return 1 on success, 0 on not enough memory error
* @see cfg_property_type
*
* Argument list must be terminated with strN = NULL. Use constructi
ons
* like this:<br>
* cfg_add_properties(con, type, str1, str2, str3=NULL)
*/
int cfg_add_properties_type(
const CFG_CONTEXT con, enum cfg_property_type type,
char *str, ...);
/**
* Remove string from property * Remove string from property
* *
* @param con initialized context * @param con initialized context
* @param type property type * @param type property type
* @param str string for removing * @param str string for removal
* @return 1 on success, 0 on not enough memory error * @return 1 on success, 0 on not enough memory error
* @see cfg_property_type * @see cfg_property_type
*/ */
int cfg_remove_property( int cfg_remove_property(
const CFG_CONTEXT con, enum cfg_property_type type, char *str); const CFG_CONTEXT con, enum cfg_property_type type, char *str);
/* }}} */ /**
/*@}*/ * Remove multiple strings from particular properties
*
* @param con initialized context
* @param type property type(s)
* @param str string(s) for removal
* @return 1 on success, 0 on not enough memory error
* @see cfg_property_type
*
* Argument list must be terminated with typeN = CFG_EOT or strN = N
ULL.
* Use constructions like this:<br>
* cfg_remove_properties(con, type1, str1, type2, str2, type3=CFG_EO
T)
*/
int cfg_remove_properties(
const CFG_CONTEXT con, enum cfg_property_type type,
char *str, ...);
/**
* Remove string from multiple properties
*
* @param con initialized context
* @param str string for removal
* @param type property type(s)
* @return 1 on success, 0 on not enough memory error
* @see cfg_property_type
*
* Argument list must be terminated with typeN = CFG_EOT. Use constr
uctions
* like this:<br>
* cfg_remove_properties(con, str, type1, type2, type3=CFG_EOT)
*/
int cfg_remove_properties_str(
const CFG_CONTEXT con, char *str, enum cfg_property_
type type, ...);
/**
* Remove multiple strings from one property
*
* @param con initialized context
* @param type property type
* @param str string(s) for removal
* @return 1 on success, 0 on not enough memory error
* @see cfg_property_type
*
* Argument list must be terminated with strN = NULL. Use constructi
ons
* like this:<br>
* cfg_add_properties(con, type, str1, str2, str3=NULL)
*/
int cfg_remove_properties_type(
const CFG_CONTEXT con, enum cfg_property_type type,
char *str, ...);
/* }}} */ /*@}*/
/** /**
* @name Functions for processing context options * @name Functions for processing context options
*/ */
/*@{*/ /*@{*/ /* {{{ */
/* {{{ */
/** /**
* Parse context * Parse context
* *
* @param con initialized context * @param con initialized context
* @return code of error (CFG_ERROR_*) or CFG_OK * @return code of error (CFG_ERROR_*)
* or CFG_OK if parsing was sucessfull
* @see cfg_error * @see cfg_error
*/ */
int cfg_parse(const CFG_CONTEXT con); int cfg_parse(const CFG_CONTEXT con);
/** /**
* Parse next option(s) and return its value (if non-zero) or error code. * Parse next option(s) and return its value (if non-zero) or error code.
* *
* @param con initialized context * @param con initialized context
* @return next option val, code of error (CFG_ERROR_*) * @return next option val, code of error (CFG_ERROR_*)
* or CFG_OK on end * or CFG_OK on end
skipping to change at line 800 skipping to change at line 912
char *cfg_get_cur_arg(const CFG_CONTEXT con); char *cfg_get_cur_arg(const CFG_CONTEXT con);
/** /**
* Return currently processed option index (argv index in command li ne * Return currently processed option index (argv index in command li ne
* context, file byte position or line position in config file conte xt) * context, file byte position or line position in config file conte xt)
* *
* @param con initialized context @return index of cur rent option * @param con initialized context @return index of cur rent option
*/ */
int cfg_get_cur_idx(const CFG_CONTEXT con); int cfg_get_cur_idx(const CFG_CONTEXT con);
/* }}} */ /* }}} */ /*@}*/
/*@}*/
/** /**
* @name Error handling functions * @name Error handling functions
*/ */
/*@{*/ /*@{*/ /* {{{ */
/* {{{ */
/** /**
* Print error string to stderr * Print error string to stderr
* *
* @param con initialized context * @param con initialized context
* @return void * @return void
*/ */
void cfg_print_error(const CFG_CONTEXT con); void cfg_print_error(const CFG_CONTEXT con);
/** /**
skipping to change at line 843 skipping to change at line 953
char *cfg_get_error_str(const CFG_CONTEXT con); char *cfg_get_error_str(const CFG_CONTEXT con);
/** /**
* Get static error string * Get static error string
* *
* @param errorcode code of libcfg error * @param errorcode code of libcfg error
* @return static error string * @return static error string
*/ */
char *cfg_get_static_error_str(const int errorcode); char *cfg_get_static_error_str(const int errorcode);
/* }}} */ /* }}} */ /*@}*/
/*@}*/
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _PLATON_CFG_H */ #endif /* _PLATON_CFG_H */
/* Modeline for ViM {{{ /* Modeline for ViM {{{
* vim:set ts=4: * vim:set ts=4:
* vim600:fdm=marker fdl=0 fdc=0: * vim600:fdm=marker fdl=0 fdc=0:
 End of changes. 44 change blocks. 
68 lines changed or deleted 194 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/