| version 1.25, 2002/03/21 14:11:53 |
version 1.26, 2002/04/04 17:10:58 |
|
|
| * http://www.platon.sk/projects/libcfg/ |
* http://www.platon.sk/projects/libcfg/ |
| */ |
*/ |
| |
|
| |
/** |
| |
* @file cfg.h |
| |
* @brief main implementation header file |
| |
* @author Ondrej Jombik <nepto@pobox.sk> |
| |
* @version \$Id$ |
| |
* @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> |
| |
|
| #include "props.h" |
#include "props.h" |
| |
|
| |
/** 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 |
#define CFG_END_OF_LIST CFG_END_OPTION /**< @ref CFG_END_OPTION */ |
| |
|
| |
|
| |
/** |
| |
* Possible return values returned by parsing functions. |
| |
*/ |
| enum cfg_error { |
enum cfg_error { |
| |
|
| /*! OK, all is right. */ |
/*@{*/ |
| |
/** OK, all is right. */ |
| CFG_ERR_OK = 0, |
CFG_ERR_OK = 0, |
| CFG_ERROR_OK = 0, |
CFG_ERROR_OK = 0, |
| CFG_OK = 0, |
CFG_OK = 0, |
| |
/*@}*/ |
| |
|
| /*! An argument is missing for an option. */ |
/** An argument is missing for an option. */ |
| CFG_ERR_NOARG = -1, |
CFG_ERR_NOARG = -1, |
| CFG_ERROR_NOARG = -1, |
CFG_ERROR_NOARG = -1, |
| |
|
| /*! An argument is not allowed for an option. */ |
/** An argument is not allowed for an option. */ |
| CFG_ERR_NOTALLOWEDARG = -2, |
CFG_ERR_NOTALLOWEDARG = -2, |
| CFG_ERROR_NOTALLOWEDARG = -2, |
CFG_ERROR_NOTALLOWEDARG = -2, |
| |
|
| /*! An option's argument could not be parsed. */ |
/** An option's argument could not be parsed. */ |
| CFG_ERR_BADOPT = -3, |
CFG_ERR_BADOPT = -3, |
| CFG_ERROR_BADOPT = -3, |
CFG_ERROR_BADOPT = -3, |
| |
|
| /*! Error in quotations. */ |
/** Error in quotations. */ |
| CFG_ERR_BADQUOTE = -4, |
CFG_ERR_BADQUOTE = -4, |
| CFG_ERROR_BADQUOTE = -4, |
CFG_ERROR_BADQUOTE = -4, |
| |
|
| /*! An option could not be converted to appropriate numeric type. */ |
/** An option could not be converted to appropriate numeric type. */ |
| CFG_ERR_BADNUMBER = -5, |
CFG_ERR_BADNUMBER = -5, |
| CFG_ERROR_BADNUMBER = -5, |
CFG_ERROR_BADNUMBER = -5, |
| |
|
| /*! A given number was too big or too small. */ |
/** A given number was too big or too small. */ |
| CFG_ERR_OVERFLOW = -6, |
CFG_ERR_OVERFLOW = -6, |
| CFG_ERROR_OVERFLOW = -6, |
CFG_ERROR_OVERFLOW = -6, |
| |
|
| /*! Multiple arguments used for single option. */ |
/** Multiple arguments used for single option. */ |
| CFG_ERR_MULTI = -7, |
CFG_ERR_MULTI = -7, |
| CFG_ERROR_MULTI = -7, |
CFG_ERROR_MULTI = -7, |
| |
|
| /*! Not enough memory. */ |
/** Not enough memory. */ |
| CFG_ERR_NOMEM = -8, |
CFG_ERR_NOMEM = -8, |
| CFG_ERROR_NOMEM = -8, |
CFG_ERROR_NOMEM = -8, |
| |
|
| /*! Stop string was found. */ |
/** Stop string was found. */ |
| CFG_ERR_STOP_STR = -9, |
CFG_ERR_STOP_STR = -9, |
| CFG_ERR_STOP_STR_FOUND = -9, |
CFG_ERR_STOP_STR_FOUND = -9, |
| CFG_ERROR_STOP_STR = -9, |
CFG_ERROR_STOP_STR = -9, |
| CFG_ERROR_STOP_STR_FOUND = -9, |
CFG_ERROR_STOP_STR_FOUND = -9, |
| |
|
| /*! No equal sign on the line. */ |
/** No equal sign on the line. */ |
| CFG_ERR_NOEQUAL = -10, |
CFG_ERR_NOEQUAL = -10, |
| CFG_ERROR_NOEQUAL = -10, |
CFG_ERROR_NOEQUAL = -10, |
| |
|
| /*! An unknown option. */ |
/** An unknown option. */ |
| CFG_ERR_UNKNOWN = -11, |
CFG_ERR_UNKNOWN = -11, |
| CFG_ERROR_UNKNOWN = -11, |
CFG_ERROR_UNKNOWN = -11, |
| |
|
| /*! File not found error. */ |
/** File not found error. */ |
| CFG_ERR_FILE_NOT_FOUND = -12, |
CFG_ERR_FILE_NOT_FOUND = -12, |
| 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 |
| |
|
| }; |
}; |
| |
|
| |
/** |
| |
* Context flags |
| |
* |
| |
* By default are @ref CFG_SKIP_FIRST, @ref CFG_POSIXLY_LEFTOVERS and |
| |
* @ref CFG_NORMAL_LEFTOVERS initialized. |
| |
*/ |
| enum cfg_flag { |
enum cfg_flag { |
| |
|
| /* Ignore multiple arguments for single option. */ |
/** Ignore multiple arguments for single option. */ |
| CFG_IGNORE_MULTI = 1, |
CFG_IGNORE_MULTI = 1, |
| |
|
| /* Ignore unknown options. */ |
/** Ignore unknown options. */ |
| CFG_IGNORE_UNKNOWN = 2, |
CFG_IGNORE_UNKNOWN = 2, |
| |
|
| /* Process also the first argument on command line. */ |
/** Skip processing of the first argument on command line. */ |
| CFG_SKIP_FIRST = 0, |
CFG_SKIP_FIRST = 0, |
| |
|
| |
/** Process also the first argument on command line. */ |
| CFG_PROCESS_FIRST = 4, |
CFG_PROCESS_FIRST = 4, |
| |
|
| /* Posixly corect or not leftover arguments. */ |
/** Posixly correct leftover arguments. */ |
| CFG_POSIXLY_LEFTOVERS = 0, |
CFG_POSIXLY_LEFTOVERS = 0, |
| |
|
| |
/** Advanced leftover arguments. */ |
| CFG_ADVANCED_LEFTOVERS = 8, |
CFG_ADVANCED_LEFTOVERS = 8, |
| |
|
| /* Strict leftover arguments initialization in file. */ |
/** Normal leftover arguments initialization in file. */ |
| CFG_NORMAL_LEFTOVERS = 0, |
CFG_NORMAL_LEFTOVERS = 0, |
| |
|
| |
/** Strict leftover arguments initialization in file. */ |
| CFG_STRICT_LEFTOVERS = 16 |
CFG_STRICT_LEFTOVERS = 16 |
| |
|
| /* Ignore all quotations in options arguments. */ |
/* Ignore all quotations in options arguments. */ |
| /* |
/* |
| CFG_USE_QUOTE = 0, |
CFG_USE_QUOTE = 0, |
| 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 |
| */ |
*/ |
| |
|
| /* TODO: |
/* TODO: |
| CFG_APPEND, |
CFG_APPEND, |
| CFG_OVERWRITE, |
CFG_OVERWRITE, |
| CFG_APPEND_MULTI_ONLY |
CFG_APPEND_MULTI_ONLY |
| */ |
*/ |
| }; |
}; |
| |
|
| enum cfg_option_type { |
enum cfg_option_type { |