X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fopt%2Fopt.h;h=55a78d8ff139e9cbe1de384d4d1da0021557e3aa;hp=9075ceed37e8c0e61e0dedb1a94df6ba4efede3f;hb=cf1b26db4b43f3e5a4448abcd45c424cc2207928;hpb=e610c8c6380caa05094294e2fa6392ba5c3f4024 diff --git a/ccan/opt/opt.h b/ccan/opt/opt.h index 9075ceed..55a78d8f 100644 --- a/ccan/opt/opt.h +++ b/ccan/opt/opt.h @@ -1,3 +1,4 @@ +/* Licensed under GPLv3+ - see LICENSE file for details */ #ifndef CCAN_OPT_H #define CCAN_OPT_H #include @@ -186,10 +187,12 @@ void opt_register_table(const struct opt_table *table, const char *desc); bool opt_parse(int *argc, char *argv[], void (*errlog)(const char *fmt, ...)); /** - * opt_free_table - free the table. + * opt_free_table - reset the opt library. * - * This frees the internal memory. Call this as the last - * opt function. + * This frees the internal memory and returns counters to zero. Call + * this as the last opt function to avoid memory leaks. You can also + * use this function to reset option handling to its initial state (no + * options registered). */ void opt_free_table(void); @@ -279,6 +282,41 @@ void opt_show_longval(char buf[OPT_SHOW_LEN], const long *l); char *opt_set_ulongval(const char *arg, unsigned long *ul); void opt_show_ulongval(char buf[OPT_SHOW_LEN], const unsigned long *ul); +/* the following setting functions accept k, M, G, T, P, or E suffixes, which + multiplies the numeric value by the corresponding power of 1000 or 1024 + (for the _si and _bi versions, respectively). + */ +char *opt_set_intval_bi(const char *arg, int *i); +char *opt_set_intval_si(const char *arg, int *i); +char *opt_set_uintval_bi(const char *arg, unsigned int *u); +char *opt_set_uintval_si(const char *arg, unsigned int *u); +char *opt_set_longval_bi(const char *arg, long *l); +char *opt_set_longval_si(const char *arg, long *l); +char *opt_set_ulongval_bi(const char *arg, unsigned long *ul); +char *opt_set_ulongval_si(const char *arg, unsigned long *ul); +char *opt_set_longlongval_bi(const char *arg, long long *ll); +char *opt_set_longlongval_si(const char *arg, long long *ll); +char *opt_set_ulonglongval_bi(const char *arg, unsigned long long *ll); +char *opt_set_ulonglongval_si(const char *arg, unsigned long long *ll); + + +void opt_show_intval_bi(char buf[OPT_SHOW_LEN], const int *x); +void opt_show_longval_bi(char buf[OPT_SHOW_LEN], const long *x); +void opt_show_longlongval_bi(char buf[OPT_SHOW_LEN], const long long *x); +void opt_show_uintval_bi(char buf[OPT_SHOW_LEN], const unsigned int *x); +void opt_show_ulongval_bi(char buf[OPT_SHOW_LEN], const unsigned long *x); +void opt_show_ulonglongval_bi(char buf[OPT_SHOW_LEN], const unsigned long long *x); + +void opt_show_intval_si(char buf[OPT_SHOW_LEN], const int *x); +void opt_show_longval_si(char buf[OPT_SHOW_LEN], const long *x); +void opt_show_longlongval_si(char buf[OPT_SHOW_LEN], const long long *x); +void opt_show_uintval_si(char buf[OPT_SHOW_LEN], const unsigned int *x); +void opt_show_ulongval_si(char buf[OPT_SHOW_LEN], const unsigned long *x); +void opt_show_ulonglongval_si(char buf[OPT_SHOW_LEN], const unsigned long long *x); + + + + /* Increment. */ char *opt_inc_intval(int *i); @@ -315,22 +353,22 @@ struct opt_table { /* Resolves to the four parameters for non-arg callbacks. */ #define OPT_CB_NOARG(cb, arg) \ OPT_NOARG, \ - cast_if_any(char *(*)(void *), (cb), 0?(cb):(cb),\ - char *(*)(typeof(*(arg))*), \ - char *(*)(const typeof(*(arg))*), \ - char *(*)(const void *)), \ + typesafe_cb_cast3(char *(*)(void *), \ + char *(*)(typeof(*(arg))*), \ + char *(*)(const typeof(*(arg))*), \ + char *(*)(const void *), (cb)), \ NULL, NULL /* Resolves to the four parameters for arg callbacks. */ #define OPT_CB_ARG(cb, show, arg) \ OPT_HASARG, NULL, \ - cast_if_any(char *(*)(const char *,void *), (cb), 0?(cb):(cb), \ - char *(*)(const char *, typeof(*(arg))*), \ - char *(*)(const char *, const typeof(*(arg))*), \ - char *(*)(const char *, const void *)), \ - cast_if_type(void (*)(char buf[], const void *), (show), \ - 0?(show):(show), \ - void (*)(char buf[], const typeof(*(arg))*)) + typesafe_cb_cast3(char *(*)(const char *,void *), \ + char *(*)(const char *, typeof(*(arg))*), \ + char *(*)(const char *, const typeof(*(arg))*), \ + char *(*)(const char *, const void *), \ + (cb)), \ + typesafe_cb_cast(void (*)(char buf[], const void *), \ + void (*)(char buf[], const typeof(*(arg))*), (show)) /* Non-typesafe register function. */ void _opt_register(const char *names, enum opt_type type,