fix: coding style
This commit is contained in:
parent
efbae5b7d6
commit
ae7fdf2f94
5 changed files with 13 additions and 11 deletions
|
|
@ -37,12 +37,12 @@ enum { CLI_OPT_ARG_TYPES };
|
||||||
|
|
||||||
void cli_set_prog_name(const char *name);
|
void cli_set_prog_name(const char *name);
|
||||||
void cli_print_options(const struct option_descriptor *opts, size_t nb_opts,
|
void cli_print_options(const struct option_descriptor *opts, size_t nb_opts,
|
||||||
t_arg_type_to_str to_str);
|
t_arg_type_to_str to_str);
|
||||||
|
|
||||||
const char *cli_arg_type_to_str(int type);
|
const char *cli_arg_type_to_str(int type);
|
||||||
|
|
||||||
enum cli_code cli_parse(int argc, char **argv, void *config,
|
enum cli_code cli_parse(int argc, char **argv, void *config,
|
||||||
const struct option_descriptor *opts, size_t nb_opts,
|
const struct option_descriptor *opts, size_t nb_opts,
|
||||||
char *opt_str, struct option *long_opts);
|
char *opt_str, struct option *long_opts);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ cli_arg_type_to_str(int type)
|
||||||
|
|
||||||
void
|
void
|
||||||
cli_print_options(const struct option_descriptor *opts, size_t nb_opts,
|
cli_print_options(const struct option_descriptor *opts, size_t nb_opts,
|
||||||
t_arg_type_to_str to_str)
|
t_arg_type_to_str to_str)
|
||||||
{
|
{
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
for (size_t i = 0; i < nb_opts; i++)
|
for (size_t i = 0; i < nb_opts; i++)
|
||||||
|
|
|
||||||
10
src/parse.c
10
src/parse.c
|
|
@ -17,14 +17,14 @@
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static void build_long_options(struct option *long_opts, size_t nb_opts,
|
static void build_long_options(struct option *long_opts, size_t nb_opts,
|
||||||
const struct option_descriptor *src);
|
const struct option_descriptor *src);
|
||||||
static void build_optstr(char *dest, const struct option_descriptor *opts,
|
static void build_optstr(char *dest, const struct option_descriptor *opts,
|
||||||
size_t nb_opts);
|
size_t nb_opts);
|
||||||
static const struct option_descriptor *find_option_handler(int opt,
|
static const struct option_descriptor *find_option_handler(int opt,
|
||||||
const struct option_descriptor *opts, size_t nb_opts);
|
const struct option_descriptor *opts, size_t nb_opts);
|
||||||
static int handle_one_option(int opt, char **argv, void *config,
|
static int handle_one_option(int opt, char **argv, void *config,
|
||||||
uint64_t *opt_tracker,
|
uint64_t *opt_tracker,
|
||||||
const struct option_descriptor *opts, size_t nb_opts);
|
const struct option_descriptor *opts, size_t nb_opts);
|
||||||
static enum cli_code error_unknown_opt(const char *current_opt);
|
static enum cli_code error_unknown_opt(const char *current_opt);
|
||||||
static enum cli_code error_invalid_opt(const char *current_opt);
|
static enum cli_code error_invalid_opt(const char *current_opt);
|
||||||
static enum cli_code error_duplicate_opt(const char *current_opt);
|
static enum cli_code error_duplicate_opt(const char *current_opt);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ cli_parse_int64(const char *s, int64_t *out)
|
||||||
errno = 0;
|
errno = 0;
|
||||||
const intmax_t v = strtoimax(s, &end, 10);
|
const intmax_t v = strtoimax(s, &end, 10);
|
||||||
|
|
||||||
if (s == end || ERANGE == errno || '\0' != *end || v < INT64_MIN || v > INT64_MAX)
|
if (s == end || ERANGE == errno || '\0' != *end || v < INT64_MIN
|
||||||
|
|| v > INT64_MAX)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
*out = (int64_t)v;
|
*out = (int64_t)v;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ cli_parse_ufloat(const char *s, float *out)
|
||||||
errno = 0;
|
errno = 0;
|
||||||
float v = strtof(s, &end);
|
float v = strtof(s, &end);
|
||||||
|
|
||||||
if (s == end || ERANGE == errno || '\0' != *end || 0 == isfinite(v) || v < 0.0f)
|
if (s == end || ERANGE == errno || '\0' != *end || 0 == isfinite(v)
|
||||||
|
|| v < 0.0f)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
*out = v;
|
*out = v;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue