liboptcfg

changeset 3:f971dfa66076

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 27 Jul 2016 04:31:40 +0300
parents 9c73004c7af3
children a6f127f3408d
files example/example.c src/optcfg.h
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/example/example.c	Fri Nov 20 17:05:39 2015 +0200
     1.2 +++ b/example/example.c	Wed Jul 27 04:31:40 2016 +0300
     1.3 @@ -15,7 +15,7 @@
     1.4  	{'b', "bar", OPT_BAR, "bar also does nothing"},
     1.5  	{0, "xyzzy", OPT_XYZZY, "xyzzy doesn't have a short option"},
     1.6  	{'h', "help", OPT_HELP, "print usage and exit"},
     1.7 -	{0, 0, -1, 0}	/* terminate with id=-1 */
     1.8 +	OPTCFG_OPTIONS_END
     1.9  };
    1.10  
    1.11  int foo, bar;
     2.1 --- a/src/optcfg.h	Fri Nov 20 17:05:39 2015 +0200
     2.2 +++ b/src/optcfg.h	Wed Jul 27 04:31:40 2016 +0300
     2.3 @@ -2,6 +2,8 @@
     2.4  #ifndef LIBOPTCFG_H_
     2.5  #define LIBOPTCFG_H_
     2.6  
     2.7 +#include <stdio.h>
     2.8 +
     2.9  struct optcfg;
    2.10  
    2.11  struct optcfg_option {
    2.12 @@ -11,9 +13,15 @@
    2.13  	char *desc;	/* text description for printing usage information */
    2.14  };
    2.15  
    2.16 +#define OPTCFG_OPTIONS_END	{0, 0, -1, 0}
    2.17 +
    2.18  typedef int (*optcfg_opt_callback)(struct optcfg *oc, int opt, void *cls);
    2.19  typedef int (*optcfg_arg_callback)(struct optcfg *oc, const char *arg, void *cls);
    2.20  
    2.21 +#ifdef __cplusplus
    2.22 +extern "C" {
    2.23 +#endif
    2.24 +
    2.25  /* initialize the optcfg object with a valid option vector terminated by an
    2.26   * entry with an opt value of -1 (other fields ignored for termination purposes)
    2.27   *
    2.28 @@ -21,7 +29,7 @@
    2.29   *   struct optcfg_option options[] = {
    2.30   *       {'f', "foo", OPT_FOO, "Makes sure the foo is bar"},
    2.31   *       {'h', "help", OPT_HELP, "Print usage information and exit"},
    2.32 - *       {0, 0, -1, 0}
    2.33 + *       OPTCFG_OPTIONS_END
    2.34   *   };
    2.35   *   struct optcfg *oc = optcfg_init(options);
    2.36   */
    2.37 @@ -75,5 +83,8 @@
    2.38  int optcfg_int_value(char *str, int *valret);
    2.39  int optcfg_float_value(char *str, float *valret);
    2.40  
    2.41 +#ifdef __cplusplus
    2.42 +}
    2.43 +#endif
    2.44  
    2.45  #endif	/* LIBOPTCFG_H_ */