- Introduces the e_cli_code enum for CLI status codes, replacing integer constants. - Updates cli_parse_arguments to return e_cli_code instead of int. - Refactors main.c, cli.h, and cli/parse.c to use the new enum.
56 lines
1.5 KiB
C
56 lines
1.5 KiB
C
#ifndef PING_CLI_H
|
|
#define PING_CLI_H
|
|
|
|
#include "ft_ping.h"
|
|
|
|
enum e_cli_code {
|
|
CLI_EXIT_SUCCESS = -1,
|
|
CLI_SUCCESS = 0,
|
|
CLI_ERROR = 1
|
|
};
|
|
|
|
|
|
typedef int (*t_option_handler)(const char *arg, t_ping_config *config);
|
|
|
|
typedef enum e_option_arg_type
|
|
{
|
|
OPT_ARG_NONE = 0,
|
|
OPT_ARG_INT,
|
|
OPT_ARG_UINT,
|
|
OPT_ARG_SECONDS,
|
|
OPT_ARG_BYTES,
|
|
OPT_ARG_TTL,
|
|
OPT_ARG_STRING
|
|
} t_option_arg_type;
|
|
|
|
typedef struct s_option_descriptor
|
|
{
|
|
char short_opt;
|
|
const char *long_opt;
|
|
int has_arg;
|
|
t_option_handler handler;
|
|
t_option_arg_type arg_type;
|
|
const char *description;
|
|
} t_option_descriptor;
|
|
|
|
extern const t_option_descriptor g_options[];
|
|
|
|
enum e_cli_code
|
|
cli_parse_arguments(int argc, char **argv, t_ping_config *config);
|
|
|
|
int cli_handle_count(const char *arg, t_ping_config *config);
|
|
int cli_handle_flood(const char *arg, t_ping_config *config);
|
|
int cli_handle_help(const char *arg, t_ping_config *config);
|
|
int cli_handle_interval(const char *arg, t_ping_config *config);
|
|
int cli_handle_quiet(const char *arg, t_ping_config *config);
|
|
int cli_handle_size(const char *arg, t_ping_config *config);
|
|
int cli_handle_timeout(const char *arg, t_ping_config *config);
|
|
int cli_handle_ttl(const char *arg, t_ping_config *config);
|
|
int cli_handle_version(const char *arg, t_ping_config *config);
|
|
int cli_handle_verbose(const char *arg, t_ping_config *config);
|
|
|
|
int cli_parse_uint64(const char *s, uint64_t *out);
|
|
int cli_parse_float(const char *s, float *out);
|
|
const char *get_optstr(void);
|
|
|
|
#endif
|