/* WARNING: This file was generated by dkct. Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: dk4opt.ctr */ /* Copyright (C) 2015-2017, Dirk Krause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above opyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef DK4OPT_H_INCLUDED /** Avoid multiple inclusions. */ #define DK4OPT_H_INCLUDED 1 #line 10 "dk4opt.ctr" /** @file Process command line option in simple programs. You can specify a set of allowed options including the option arguments types. After processing command line arguments you can simply check which options were used and obtain option argument values. */ #ifndef DK4CONF_H_INCLUDED #include "dk4conf.h" #endif #ifndef DK4TYPES_H_INCLUDED #include "dk4types.h" #endif #ifndef DK4ERROR_H_INCLUDED #include "dk4error.h" #endif /** Option specification for application module. */ typedef struct { dkChar c; /**< Short option character. */ const dkChar *longopt; /**< Long option string. */ int argtype; /**< Argument type. */ } dk4_option_specification_t; /** Option values can be different types. */ typedef union { dkChar *t; /**< String value. */ double d; /**< Double value. */ dk4_im_t i; /**< Integer value. */ dk4_um_t u; /**< Unsigned integer value. */ size_t s; /**< Size value. */ int b; /**< Boolean value. */ } dk4_option_value_t; /** Option with value. */ typedef struct { dk4_option_specification_t spec; /**< Option specification. */ dk4_option_value_t val; /**< Option value. */ int found; /**< Flag: Option found in cmd line. */ } dk4_option_t; /** Argument types. */ enum { /** No argument expected. */ DK4_OPT_ARG_NONE = 1, /** Boolean value expected. */ DK4_OPT_ARG_BOOL , /** Size specification expected. */ DK4_OPT_ARG_SIZE , /** Signed integer value expected. */ DK4_OPT_ARG_INT , /** Unsigned integer value expected. */ DK4_OPT_ARG_UNSIGNED , /** Double value expected. */ DK4_OPT_ARG_DOUBLE , /** String value expected. */ DK4_OPT_ARG_STRING }; #ifdef __cplusplus extern "C" { #endif /** Create option object. CRT on Windows: Optional. @param spec Specifications for the option. @param erp Error report, may be NULL. @return Pointer to new option object on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if spec is NULL, - DK4_E_SYNTAX
if neither short nor long option is defined in spec, - DK4_E_MEMORY
if the memory allocation failed. */ dk4_option_t * dk4opt_open(const dk4_option_specification_t *spec, dk4_er_t *erp); /** Retrieve boolean value (as int) from option. CRT on Windows: Optional. @param dptr Pointer to destination variable. @param optptr Option to retrieve value from. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or optptr is NULL or optptr is configured for another data type, - DK4_E_NOT_FOUND
if the option was not specified on the command line, - DK4_E_SYNTAX
if a string is stored not representing a boolean or the option was configured with an incompatible type. */ int dk4opt_get_bool(int *dptr, dk4_option_t *optptr, dk4_er_t *erp); /** Retrieve size_t value from option. CRT on Windows: Optional. @param dptr Pointer to destination variable. @param optptr Option to retrieve value from. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or optptr is NULL or optptr is configured for another data type, - DK4_E_NOT_FOUND
if the option was not specified on the command line, - DK4_E_SYNTAX
if the option was configured for an incompatible type or the option argument string can not be converted to a size_t, - DK4_E_MATH_OVERFLOW
if the option was configured for another numeric type and conversion results in an overflow. */ int dk4opt_get_size(size_t *dptr, dk4_option_t *optptr, dk4_er_t *erp); /** Retrieve integer value (dk4_im_t) from option. CRT on Windows: Optional. @param dptr Pointer to destination variable. @param optptr Option to retrieve value from. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or optptr is NULL or optptr is configured for another data type, - DK4_E_NOT_FOUND
if the option was not specified on the command line, - DK4_E_SYNTAX
if the option was configured for an incompatible type or the option argument string does not represent an integer number, - DK4_E_MATH_OVERFLOW
if the option was configured for another numeric type and conversion results in an overflow. */ int dk4opt_get_int(dk4_im_t *dptr, dk4_option_t *optptr, dk4_er_t *erp); /** Retrieve unsigned integer value (dk4_um_t) from option. CRT on Windows: Optional. @param dptr Pointer to destination variable. @param optptr Option to retrieve value from. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or optptr is NULL or optptr is configured for another data type, - DK4_E_NOT_FOUND
if the option was not specified on the command line, - DK4_E_SYNTAX
if the option was configured for an incompatible data type or the option string does not represent an integer number, - DK4_E_MATH_OVERFLOW
if the option was configured for an incompatible numeric type and a negative value is stored. */ int dk4opt_get_unsigned(dk4_um_t *dptr, dk4_option_t *optptr, dk4_er_t *erp); /** Retrieve double value from option. CRT on Windows: Optional. @param dptr Pointer to destination variable. @param optptr Option to retrieve value from. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or optptr is NULL or optptr is configured for another data type, - DK4_E_NOT_FOUND
if the option was not specified on the command line, - DK4_E_SYNTAX
if the option was configured for an incompatible data type or the string stored as option argument does not represent a double number. */ int dk4opt_get_double(double *dptr, dk4_option_t *optptr, dk4_er_t *erp); /** Retrieve string value from option. CRT on Windows: Optional, disabling CRT reduces functionality as we can not convert double values to strings. @param dptr Pointer to destination buffer. @param szdptr Size of destination buffer (number of dkChar). @param optptr Option to retrieve value from. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or optptr is NULL or optptr is configured for another data type, - DK4_E_NOT_FOUND
if the option was not specified on the command line. - DK4_E_SYNTAX
if the option was configured for an incompatible data type, - DK4_E_BUFFER_TOO_SMALL
if the destination buffer is too small to hold a conversion result, - DK4_E_NOT_SUPPORTED
if the option was configured for the double data type and the use of sprintf() was denied during setup. */ int dk4opt_get_string( dkChar *dptr, size_t szdptr, dk4_option_t *optptr, dk4_er_t *erp ); /** Destroy option object, release memory. CRT on Windows: Optional. @param optptr Option object to destroy. */ void dk4opt_close(dk4_option_t *optptr); /** Compare option against other option or char or string. CRT on Windows: Optional. @param l Left pointer, always an option. @param r Right pointer, type depends on cr. @param cr Comparison criteria: 0=option/option by short character, 1=option/character, 2=option/option by long option text, 3=option/text. @return Comparison result. */ int dk4option_compare(const void *l, const void *r, int cr); /** Process command line options provided to the main function. @param optptr Options array. @param szoptptr Number of elements in array. @param argc Number of command line arguments. @param argv Command line arguments array. @param filenames Pointer array to store file names. @param nfilenames Elements in array (in: size, out: used). @param progname Flag: Argument 0 is program name. @param logstderr Flag: Logging to stderr allowed. @param erp Error report, may be NULL. @return 1 on success, 0 on error. */ int dk4opt_process_argv( dk4_option_t *optptr, size_t szoptptr, int argc, dkChar *argv[], dkChar **filenames, size_t *nfilenames, int progname, int logstderr, dk4_er_t *erp ); #ifdef __cplusplus } #endif #endif