From f6ca69f795b56c7b09ddf9db9f5b57dce9970e0a Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Tue, 3 Mar 2026 18:37:11 +0100 Subject: [PATCH] feat(cli): refactor CLI move utilities, and improve build/version metadata - Move CLI internal headers to `includes/internal/cli/` - Split CLI handler and parsing declarations across dedicated internal headers - Move handler map to `option_map.c` and properly update references - Relocate CLI utility source and test files from `utils` to `parse_utils` - Refactor `cli.h` to only expose the public interface, move internal typedefs/functions out - Update build system: add conditional git commit detection --- Makefile | 7 +++ includes/cli.h | 41 ----------------- includes/internal/cli/arg_handler.h | 44 ++++++++++++++++++ includes/internal/cli/messages.h | 7 +++ .../{cli_opt.h => internal/cli/options.h} | 3 +- includes/internal/cli/parse_utils.h | 9 ++++ sources.mk | 15 +++--- src/cli/handlers/handle_count.c | 3 +- src/cli/handlers/handle_flood.c | 1 - src/cli/handlers/handle_help.c | 46 ++----------------- src/cli/handlers/handle_interval.c | 3 +- src/cli/handlers/handle_quiet.c | 1 - src/cli/handlers/handle_size.c | 4 +- src/cli/handlers/handle_timeout.c | 3 +- src/cli/handlers/handle_ttl.c | 4 +- src/cli/handlers/handle_version.c | 16 ++----- .../handlers/{handler_map.c => option_map.c} | 7 +-- src/cli/messages/error.c | 0 src/cli/messages/help.c | 45 ++++++++++++++++++ src/cli/messages/version.c | 17 +++++++ src/cli/parse.c | 14 ++++-- src/cli/parse_utils/get_optstr.c | 40 ++++++++++++++++ src/cli/{utils => parse_utils}/parse_float.c | 0 src/cli/{utils => parse_utils}/parse_int.c | 1 - src/cli/utils/get_optstr.c | 36 --------------- src/main.c | 1 - tests/cli/handlers/test_handle_count.c | 1 + tests/cli/handlers/test_handle_flood.c | 5 +- tests/cli/handlers/test_handle_help.c | 1 + tests/cli/handlers/test_handle_interval.c | 1 + tests/cli/handlers/test_handle_quiet.c | 1 + tests/cli/handlers/test_handle_size.c | 1 + tests/cli/handlers/test_handle_timeout.c | 1 + tests/cli/handlers/test_handle_ttl.c | 1 + tests/cli/handlers/test_handle_verbose.c | 1 + tests/cli/handlers/test_handle_version.c | 1 + tests/cli/handlers/test_handler_map.c | 2 +- .../{utils => parse_utils}/test_parse_float.c | 2 +- .../{utils => parse_utils}/test_parse_int.c | 2 +- 39 files changed, 224 insertions(+), 164 deletions(-) create mode 100644 includes/internal/cli/arg_handler.h create mode 100644 includes/internal/cli/messages.h rename includes/{cli_opt.h => internal/cli/options.h} (94%) create mode 100644 includes/internal/cli/parse_utils.h rename src/cli/handlers/{handler_map.c => option_map.c} (76%) create mode 100644 src/cli/messages/error.c create mode 100644 src/cli/messages/help.c create mode 100644 src/cli/messages/version.c create mode 100644 src/cli/parse_utils/get_optstr.c rename src/cli/{utils => parse_utils}/parse_float.c (100%) rename src/cli/{utils => parse_utils}/parse_int.c (94%) delete mode 100644 src/cli/utils/get_optstr.c rename tests/cli/{utils => parse_utils}/test_parse_float.c (97%) rename tests/cli/{utils => parse_utils}/test_parse_int.c (97%) diff --git a/Makefile b/Makefile index b17a3d7..84097ae 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,12 @@ VERSION := 0.0.1 BUILD_DATE := $(shell git log -1 --format=%cd --date=format:'%Y-%m-%d %H:%M:%S' 2>/dev/null || date -u '+%Y-%m-%d %H:%M:%S') GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "nogit") +ifeq ($(GIT_COMMIT),nogit) + HAS_GIT_COMMIT=0 +else + HAS_GIT_COMMIT=1 +endif + .DEFAULT_GOAL := all MAKEFLAGS += --no-print-directory @@ -52,6 +58,7 @@ update-version-header: echo "#define PING_VERSION \"$(VERSION)\"" >> $$NEW_HEADER; \ echo "#define PING_BUILD_DATE \"$(BUILD_DATE)\"" >> $$NEW_HEADER; \ echo "#define PING_GIT_COMMIT \"$(GIT_COMMIT)\"" >> $$NEW_HEADER; \ + echo "#define PING_HAS_GIT_COMMIT $(HAS_GIT_COMMIT)" >> $$NEW_HEADER; \ echo "" >> $$NEW_HEADER; \ echo "typedef struct s_prog_name" >> $$NEW_HEADER; \ echo "{" >> $$NEW_HEADER; \ diff --git a/includes/cli.h b/includes/cli.h index 89900d4..4508e3f 100644 --- a/includes/cli.h +++ b/includes/cli.h @@ -9,48 +9,7 @@ enum e_cli_code { 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 diff --git a/includes/internal/cli/arg_handler.h b/includes/internal/cli/arg_handler.h new file mode 100644 index 0000000..c9f7ec6 --- /dev/null +++ b/includes/internal/cli/arg_handler.h @@ -0,0 +1,44 @@ +#ifndef CLI_INTERNAL_ARG_HANDLER +#define CLI_INTERNAL_ARG_HANDLER + +#include "ft_ping.h" + +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[]; + +const char *cli_get_optstr(void); + +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); + +#endif diff --git a/includes/internal/cli/messages.h b/includes/internal/cli/messages.h new file mode 100644 index 0000000..deb8375 --- /dev/null +++ b/includes/internal/cli/messages.h @@ -0,0 +1,7 @@ +#ifndef CLI_INTERNAL_MESSAGES +#define CLI_INTERNAL_MESSAGES + +void print_help(void); +void print_version(void); + +#endif diff --git a/includes/cli_opt.h b/includes/internal/cli/options.h similarity index 94% rename from includes/cli_opt.h rename to includes/internal/cli/options.h index a4bec58..c6e761c 100644 --- a/includes/cli_opt.h +++ b/includes/internal/cli/options.h @@ -93,6 +93,7 @@ enum { CLI_OPT_LEN = (0 CLI_OPTIONS_LIST) }; + (1 * (has_arg == no_argument) \ + (2 * (has_arg == required_argument) \ + (3 * (has_arg == optional_argument)))) -enum { CLI_OPT_STR_LEN = (0 CLI_OPTIONS_LIST) }; +enum { CLI_OPT_STR_LEN = (1 CLI_OPTIONS_LIST) }; +/* +1 for ':' to disable getopt error messages */ #endif diff --git a/includes/internal/cli/parse_utils.h b/includes/internal/cli/parse_utils.h new file mode 100644 index 0000000..8b54717 --- /dev/null +++ b/includes/internal/cli/parse_utils.h @@ -0,0 +1,9 @@ +#ifndef CLI_INTERNAL_PARSE_UTILS +#define CLI_INTERNAL_PARSE_UTILS + +#include + +int cli_parse_uint64(const char *s, uint64_t *out); +int cli_parse_float(const char *s, float *out); + +#endif diff --git a/sources.mk b/sources.mk index 899674f..b652f44 100644 --- a/sources.mk +++ b/sources.mk @@ -7,16 +7,17 @@ SRCS = $(SRC_DIR)/main.c \ $(SRC_DIR)/cli/handlers/handle_help.c \ $(SRC_DIR)/cli/handlers/handle_interval.c \ $(SRC_DIR)/cli/handlers/handle_quiet.c \ - $(SRC_DIR)/cli/handlers/handler_map.c \ + $(SRC_DIR)/cli/handlers/option_map.c \ $(SRC_DIR)/cli/handlers/handle_size.c \ $(SRC_DIR)/cli/handlers/handle_timeout.c \ $(SRC_DIR)/cli/handlers/handle_ttl.c \ $(SRC_DIR)/cli/handlers/handle_version.c \ $(SRC_DIR)/cli/handlers/handle_verbose.c \ - $(SRC_DIR)/cli/utils/parse_int.c \ - $(SRC_DIR)/cli/utils/parse_float.c \ - $(SRC_DIR)/cli/utils/get_optstr.c \ - + $(SRC_DIR)/cli/parse_utils/parse_int.c \ + $(SRC_DIR)/cli/parse_utils/parse_float.c \ + $(SRC_DIR)/cli/parse_utils/get_optstr.c \ + $(SRC_DIR)/cli/messages/help.c \ + $(SRC_DIR)/cli/messages/version.c \ TESTS_DIR = tests TESTS = $(TESTS_DIR)/test_main.c \ @@ -31,6 +32,6 @@ TESTS = $(TESTS_DIR)/test_main.c \ $(TESTS_DIR)/cli/handlers/test_handle_ttl.c \ $(TESTS_DIR)/cli/handlers/test_handle_version.c \ $(TESTS_DIR)/cli/handlers/test_handle_verbose.c \ - $(TESTS_DIR)/cli/utils/test_parse_int.c \ - $(TESTS_DIR)/cli/utils/test_parse_float.c \ + $(TESTS_DIR)/cli/parse_utils/test_parse_int.c \ + $(TESTS_DIR)/cli/parse_utils/test_parse_float.c \ diff --git a/src/cli/handlers/handle_count.c b/src/cli/handlers/handle_count.c index 917f5aa..48c0ddc 100644 --- a/src/cli/handlers/handle_count.c +++ b/src/cli/handlers/handle_count.c @@ -1,8 +1,9 @@ -#include #include #include #include "cli.h" +#include "internal/cli/arg_handler.h" +#include "internal/cli/parse_utils.h" int cli_handle_count(const char *arg, t_ping_config *config) diff --git a/src/cli/handlers/handle_flood.c b/src/cli/handlers/handle_flood.c index 53e15f5..94b1fbd 100644 --- a/src/cli/handlers/handle_flood.c +++ b/src/cli/handlers/handle_flood.c @@ -1,5 +1,4 @@ #include "cli.h" -#include "ft_ping.h" #include "ft_ping_flags.h" int diff --git a/src/cli/handlers/handle_help.c b/src/cli/handlers/handle_help.c index 6409107..751da0d 100644 --- a/src/cli/handlers/handle_help.c +++ b/src/cli/handlers/handle_help.c @@ -1,52 +1,14 @@ -#include -#include -#include - #include "cli.h" -#include "cli_opt.h" -#include "ft_ping.h" - -/* Forward declarations */ -static const char * option_arg_type_to_str(t_option_arg_type type); -/* -------------------- */ +#include "internal/cli/arg_handler.h" +#include "internal/cli/messages.h" int cli_handle_help(const char *arg, t_ping_config *config) { - (void)config; (void)arg; + (void)config; - printf("ft_ping - Send ICMP ECHO_REQUEST to network hosts\n"); - printf("Usage: ft_ping [options] \n\n"); - printf("Options:\n"); + print_help(); - for (size_t i = 0; i < CLI_OPT_LEN; ++i) - { - const t_option_descriptor *opt = &g_options[i]; - const char *argstr = option_arg_type_to_str(opt->arg_type); - - printf(" -%c, --%-10s %-8s %s\n", - opt->short_opt, - opt->long_opt, - argstr[0] ? argstr : "", - opt->description - ); - } return CLI_EXIT_SUCCESS; } - -static const char * -option_arg_type_to_str(t_option_arg_type type) -{ - switch (type) - { - case OPT_ARG_NONE: return ""; - case OPT_ARG_INT: return ""; - case OPT_ARG_UINT: return ""; - case OPT_ARG_SECONDS: return ""; - case OPT_ARG_BYTES: return ""; - case OPT_ARG_TTL: return ""; - case OPT_ARG_STRING: return ""; - default: return ""; - } -} diff --git a/src/cli/handlers/handle_interval.c b/src/cli/handlers/handle_interval.c index 99b6324..74d774b 100644 --- a/src/cli/handlers/handle_interval.c +++ b/src/cli/handlers/handle_interval.c @@ -1,5 +1,6 @@ #include "cli.h" -#include "ft_ping.h" +#include "internal/cli/arg_handler.h" +#include "internal/cli/parse_utils.h" #include #include diff --git a/src/cli/handlers/handle_quiet.c b/src/cli/handlers/handle_quiet.c index f63300b..39bc729 100644 --- a/src/cli/handlers/handle_quiet.c +++ b/src/cli/handlers/handle_quiet.c @@ -1,4 +1,3 @@ -#include "ft_ping.h" #include "cli.h" #include "ft_ping_flags.h" diff --git a/src/cli/handlers/handle_size.c b/src/cli/handlers/handle_size.c index b238129..d06c951 100644 --- a/src/cli/handlers/handle_size.c +++ b/src/cli/handlers/handle_size.c @@ -1,7 +1,7 @@ #include "cli.h" -#include "ft_ping.h" +#include "internal/cli/arg_handler.h" +#include "internal/cli/parse_utils.h" -#include #include #include diff --git a/src/cli/handlers/handle_timeout.c b/src/cli/handlers/handle_timeout.c index be75aa5..ee10581 100644 --- a/src/cli/handlers/handle_timeout.c +++ b/src/cli/handlers/handle_timeout.c @@ -1,5 +1,6 @@ #include "cli.h" -#include "ft_ping.h" +#include "internal/cli/arg_handler.h" +#include "internal/cli/parse_utils.h" #include #include diff --git a/src/cli/handlers/handle_ttl.c b/src/cli/handlers/handle_ttl.c index 1e16c82..6562b07 100644 --- a/src/cli/handlers/handle_ttl.c +++ b/src/cli/handlers/handle_ttl.c @@ -1,7 +1,7 @@ #include "cli.h" -#include "ft_ping.h" +#include "internal/cli/arg_handler.h" +#include "internal/cli/parse_utils.h" -#include #include #include diff --git a/src/cli/handlers/handle_version.c b/src/cli/handlers/handle_version.c index 81d9170..546e6e0 100644 --- a/src/cli/handlers/handle_version.c +++ b/src/cli/handlers/handle_version.c @@ -1,8 +1,6 @@ #include "cli.h" -#include "ft_ping.h" -#include "version_gen.h" - -#include +#include "internal/cli/arg_handler.h" +#include "internal/cli/messages.h" int cli_handle_version(const char *arg, t_ping_config *config) @@ -10,14 +8,6 @@ cli_handle_version(const char *arg, t_ping_config *config) (void)arg; (void)config; - printf("%s version %s\n", g_prog_name.name, PING_VERSION); - printf("Copyright (C) 2026 lohhiicccc\n"); - printf("License GPLv3+:"); - printf("GNU GPL version 3 or later \n"); - printf("This is free software: you are free to change and redistribute it.\n"); - printf("There is NO WARRANTY, to the extent permitted by law.\n"); - printf("\n"); - printf("Build: %s (commit %s)\n", PING_BUILD_DATE, PING_GIT_COMMIT); - + print_version(); return CLI_EXIT_SUCCESS; } diff --git a/src/cli/handlers/handler_map.c b/src/cli/handlers/option_map.c similarity index 76% rename from src/cli/handlers/handler_map.c rename to src/cli/handlers/option_map.c index 7faf992..dd4434d 100644 --- a/src/cli/handlers/handler_map.c +++ b/src/cli/handlers/option_map.c @@ -1,8 +1,5 @@ -#include -#include - -#include "cli.h" -#include "cli_opt.h" +#include "internal/cli/arg_handler.h" +#include "internal/cli/options.h" #undef X #define X(short_opt, long_opt, has_arg, handler, arg_type, desc) \ diff --git a/src/cli/messages/error.c b/src/cli/messages/error.c new file mode 100644 index 0000000..e69de29 diff --git a/src/cli/messages/help.c b/src/cli/messages/help.c new file mode 100644 index 0000000..01e4241 --- /dev/null +++ b/src/cli/messages/help.c @@ -0,0 +1,45 @@ +#include + +#include "internal/cli/arg_handler.h" +#include "internal/cli/options.h" + +/* Forward declarations */ +static inline const char * option_arg_type_to_str(t_option_arg_type type); +/* -------------------- */ + +void +print_help(void) +{ + printf("ft_ping - Send ICMP ECHO_REQUEST to network hosts\n"); + printf("Usage: ft_ping [options] \n\n"); + printf("Options:\n"); + + for (size_t i = 0; i < CLI_OPT_LEN; ++i) + { + const t_option_descriptor *opt = &g_options[i]; + const char *argstr = option_arg_type_to_str(opt->arg_type); + + printf(" -%c, --%-10s %-8s %s\n", + opt->short_opt, + opt->long_opt, + argstr[0] ? argstr : "", + opt->description + ); + } +} + +static inline const char * +option_arg_type_to_str(t_option_arg_type type) +{ + switch (type) + { + case OPT_ARG_NONE: return ""; + case OPT_ARG_INT: return ""; + case OPT_ARG_UINT: return ""; + case OPT_ARG_SECONDS: return ""; + case OPT_ARG_BYTES: return ""; + case OPT_ARG_TTL: return ""; + case OPT_ARG_STRING: return ""; + default: return ""; + } +} diff --git a/src/cli/messages/version.c b/src/cli/messages/version.c new file mode 100644 index 0000000..d298565 --- /dev/null +++ b/src/cli/messages/version.c @@ -0,0 +1,17 @@ +#include "version_gen.h" +#include + +void +print_version(void) +{ + printf("%s version %s\n", g_prog_name.name, PING_VERSION); + printf("Copyright (C) 2026 lohhiicccc\n"); + printf("License GPLv3+:"); + printf("GNU GPL version 3 or later \n"); + printf("This is free software: you are free to change and redistribute it.\n"); + printf("There is NO WARRANTY, to the extent permitted by law.\n"); + printf("\n"); +#if PING_HAS_GIT_COMMIT + printf("Build: %s (commit %s)\n", PING_BUILD_DATE, PING_GIT_COMMIT); +#endif +} diff --git a/src/cli/parse.c b/src/cli/parse.c index 78accdf..c970615 100644 --- a/src/cli/parse.c +++ b/src/cli/parse.c @@ -3,10 +3,17 @@ #include #include "cli.h" -#include "cli_opt.h" -#include "ft_ping.h" +#include "internal/cli/arg_handler.h" +#include "internal/cli/options.h" #include "ft_ping_const.h" +/* Map -? to -h to support help shortcut */ +#define HANDLE_QUESTION_MARK(opt) \ + do { \ + if (opt == '?' && (optopt) == '?') \ + opt = 'h'; \ + } while (0) + /* Forward declatation */ static void init_config(t_ping_config *config); static void build_long_options(struct option *long_opts, size_t nb_opts, @@ -24,8 +31,9 @@ cli_parse_arguments(int argc, char **argv, t_ping_config *config) init_config(config); build_long_options(long_opts, CLI_OPT_LEN, g_options); - while (-1 != (opt = getopt_long(argc, argv, get_optstr(), long_opts, NULL))) + while (-1 != (opt = getopt_long(argc, argv, cli_get_optstr(), long_opts, NULL))) { + HANDLE_QUESTION_MARK(opt); res = handle_one_option(opt, optarg, config); if (0 != res) return res; diff --git a/src/cli/parse_utils/get_optstr.c b/src/cli/parse_utils/get_optstr.c new file mode 100644 index 0000000..8bc57fd --- /dev/null +++ b/src/cli/parse_utils/get_optstr.c @@ -0,0 +1,40 @@ +#include "internal/cli/arg_handler.h" +#include "internal/cli/options.h" + +/* Forward declarations */ +static void init_opt_str(char *str); +/* -------------------- */ + +const char * +cli_get_optstr(void) +{ + /* Static string to act like a global */ + static char opt_str[CLI_OPT_STR_LEN] = ""; + + /* Lazy init */ + if ('\0' == *opt_str) + init_opt_str(opt_str); + + return opt_str; +} + +static void +init_opt_str(char *dest) +{ + /* Mute default error messages */ + dest[0] = ':'; + + size_t str_i = 1; + for (size_t opt_i = 0; opt_i < CLI_OPT_LEN; ++opt_i) + { + dest[str_i++] = g_options[opt_i].short_opt; + switch (g_options[opt_i].has_arg) + { + case optional_argument: dest[str_i++] = ':'; /* fall through */ + case required_argument: dest[str_i++] = ':'; break; + default: break; + } + } + dest[str_i] = '\0'; + return; +} diff --git a/src/cli/utils/parse_float.c b/src/cli/parse_utils/parse_float.c similarity index 100% rename from src/cli/utils/parse_float.c rename to src/cli/parse_utils/parse_float.c diff --git a/src/cli/utils/parse_int.c b/src/cli/parse_utils/parse_int.c similarity index 94% rename from src/cli/utils/parse_int.c rename to src/cli/parse_utils/parse_int.c index f6ec7b5..9a3cdeb 100644 --- a/src/cli/utils/parse_int.c +++ b/src/cli/parse_utils/parse_int.c @@ -1,6 +1,5 @@ #include #include -#include #include int diff --git a/src/cli/utils/get_optstr.c b/src/cli/utils/get_optstr.c deleted file mode 100644 index aa95b49..0000000 --- a/src/cli/utils/get_optstr.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "cli.h" -#include "cli_opt.h" -#include - -/* Forward declarations */ -static void init_opt_str(char *str); -/* -------------------- */ - -const char * -get_optstr(void) -{ - static char opt_str[CLI_OPT_STR_LEN] = ""; - - if ('\0' == *opt_str) - init_opt_str(opt_str); - - return opt_str; -} - -static void -init_opt_str(char *opt_str) -{ - size_t str_i = 0; - for (size_t opt_i = 0; opt_i < CLI_OPT_LEN; ++opt_i) - { - opt_str[str_i++] = g_options[opt_i].short_opt; - switch (g_options[opt_i].has_arg) - { - case optional_argument: opt_str[str_i++] = ':'; /* fall through */ - case required_argument: opt_str[str_i++] = ':'; break; - default: break; - } - } - opt_str[str_i] = '\0'; - return; -} diff --git a/src/main.c b/src/main.c index d1ac047..e54c80e 100644 --- a/src/main.c +++ b/src/main.c @@ -4,7 +4,6 @@ #include #include "cli.h" -#include "ft_ping.h" #include "version_gen.h" /* Forward declarations */ diff --git a/tests/cli/handlers/test_handle_count.c b/tests/cli/handlers/test_handle_count.c index 9090384..be6cf38 100644 --- a/tests/cli/handlers/test_handle_count.c +++ b/tests/cli/handlers/test_handle_count.c @@ -1,5 +1,6 @@ #include #include "cli.h" +#include "internal/arg_handler.h" /* Test 1: basic test */ Test(cli_handle_count, valid_number) diff --git a/tests/cli/handlers/test_handle_flood.c b/tests/cli/handlers/test_handle_flood.c index 84ea858..1c0cd4e 100644 --- a/tests/cli/handlers/test_handle_flood.c +++ b/tests/cli/handlers/test_handle_flood.c @@ -1,6 +1,7 @@ -#include "cli.h" -#include "ft_ping_flags.h" #include +#include "cli.h" +#include "internal/arg_handler.h" +#include "ft_ping_flags.h" /* Test 1: test flag*/ Test(handle_flood, flag_test) diff --git a/tests/cli/handlers/test_handle_help.c b/tests/cli/handlers/test_handle_help.c index 206101f..f275172 100644 --- a/tests/cli/handlers/test_handle_help.c +++ b/tests/cli/handlers/test_handle_help.c @@ -1,5 +1,6 @@ #include #include "cli.h" +#include "internal/arg_handler.h" /* Test 1: exit code test */ Test(handle_help, exit_code) diff --git a/tests/cli/handlers/test_handle_interval.c b/tests/cli/handlers/test_handle_interval.c index 4e1d26e..2a541c2 100644 --- a/tests/cli/handlers/test_handle_interval.c +++ b/tests/cli/handlers/test_handle_interval.c @@ -1,5 +1,6 @@ #include #include "cli.h" +#include "internal/arg_handler.h" /* Test 1: basic test */ Test(cli_handle_interval, valid_number) diff --git a/tests/cli/handlers/test_handle_quiet.c b/tests/cli/handlers/test_handle_quiet.c index 319cb98..9218c16 100644 --- a/tests/cli/handlers/test_handle_quiet.c +++ b/tests/cli/handlers/test_handle_quiet.c @@ -1,5 +1,6 @@ #include "cli.h" #include "ft_ping_flags.h" +#include "internal/arg_handler.h" #include /* Test 1: test flag*/ diff --git a/tests/cli/handlers/test_handle_size.c b/tests/cli/handlers/test_handle_size.c index 51de939..ef3023c 100644 --- a/tests/cli/handlers/test_handle_size.c +++ b/tests/cli/handlers/test_handle_size.c @@ -1,5 +1,6 @@ #include #include "cli.h" +#include "internal/arg_handler.h" /* Test 1: basic test */ Test(cli_handle_size, valid_number) diff --git a/tests/cli/handlers/test_handle_timeout.c b/tests/cli/handlers/test_handle_timeout.c index 9f3eb62..295a81f 100644 --- a/tests/cli/handlers/test_handle_timeout.c +++ b/tests/cli/handlers/test_handle_timeout.c @@ -1,5 +1,6 @@ #include #include "cli.h" +#include "internal/arg_handler.h" /* Test 1: basic test */ Test(cli_handle_timeout, valid_number) diff --git a/tests/cli/handlers/test_handle_ttl.c b/tests/cli/handlers/test_handle_ttl.c index 416f941..cf5b317 100644 --- a/tests/cli/handlers/test_handle_ttl.c +++ b/tests/cli/handlers/test_handle_ttl.c @@ -1,5 +1,6 @@ #include #include "cli.h" +#include "internal/arg_handler.h" /* Test 1: basic test */ Test(cli_handle_ttl, valid_number) diff --git a/tests/cli/handlers/test_handle_verbose.c b/tests/cli/handlers/test_handle_verbose.c index 4035081..03f338d 100644 --- a/tests/cli/handlers/test_handle_verbose.c +++ b/tests/cli/handlers/test_handle_verbose.c @@ -1,5 +1,6 @@ #include "cli.h" #include "ft_ping_flags.h" +#include "internal/arg_handler.h" #include /* Test 1: test flag*/ diff --git a/tests/cli/handlers/test_handle_version.c b/tests/cli/handlers/test_handle_version.c index bfbe8b8..970e1d9 100644 --- a/tests/cli/handlers/test_handle_version.c +++ b/tests/cli/handlers/test_handle_version.c @@ -1,5 +1,6 @@ #include #include "cli.h" +#include "internal/arg_handler.h" /* Test 1: exit code test */ Test(handle_version, exit_code) diff --git a/tests/cli/handlers/test_handler_map.c b/tests/cli/handlers/test_handler_map.c index aaea835..4116f94 100644 --- a/tests/cli/handlers/test_handler_map.c +++ b/tests/cli/handlers/test_handler_map.c @@ -1,4 +1,4 @@ -#include "cli.h" +#include "internal/arg_handler.h" #include #include diff --git a/tests/cli/utils/test_parse_float.c b/tests/cli/parse_utils/test_parse_float.c similarity index 97% rename from tests/cli/utils/test_parse_float.c rename to tests/cli/parse_utils/test_parse_float.c index 48c98b6..a835119 100644 --- a/tests/cli/utils/test_parse_float.c +++ b/tests/cli/parse_utils/test_parse_float.c @@ -1,5 +1,5 @@ #include -#include "cli.h" +#include "internal/parse_utils.h" /* Test 1: Valid simple number */ Test(parse_float, valid_number) diff --git a/tests/cli/utils/test_parse_int.c b/tests/cli/parse_utils/test_parse_int.c similarity index 97% rename from tests/cli/utils/test_parse_int.c rename to tests/cli/parse_utils/test_parse_int.c index a54cc26..e500e7a 100644 --- a/tests/cli/utils/test_parse_int.c +++ b/tests/cli/parse_utils/test_parse_int.c @@ -1,6 +1,6 @@ #include #include -#include "cli.h" +#include "internal/parse_utils.h" /* Test 1: Valid simple number */ Test(parse_uint64, valid_number)