From 7d027578c0fb6cde67a7d96e004b94f88402b251 Mon Sep 17 00:00:00 2001 From: Marcin Borowicz Date: Sun, 12 Jan 2025 02:07:46 +0100 Subject: [PATCH] remove warnings --- README.md | 16 ++++++++-------- examples/BasicCLI/cli.c | 6 +++--- examples/linux/src/adc.c | 4 ++-- examples/linux/src/gpio.c | 8 ++++---- examples/linux/src/mem.c | 4 ++-- src/clip_cmd_call.c | 1 - src/clip_defs.h | 18 ++++++++++++++++-- src/clip_utils_arg.c | 1 - 8 files changed, 35 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index a7f4dbe..0738312 100644 --- a/README.md +++ b/README.md @@ -114,11 +114,11 @@ CLIP_DEF_ROOT_COMMAND(g_adc_cmd, "adc", "control adc driver", NULL) CLIP_DEF_COMMAND("read", "read input", adc_read_callback) CLIP_DEF_WITH_ARGS() /* there will be 1 required argument in "adc read" command */ CLIP_DEF_ARGUMENT("channel", "channel number", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND("set", "set reference", adc_set_callback) CLIP_DEF_WITH_ARGS() /* there will be 1 required argument in "adc set" command */ CLIP_DEF_ARGUMENT("vref", "voltage reference", CLIP_ARG_TYPE_FLOAT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND("start", "start sampling", adc_start_callback) CLIP_DEF_COMMAND_END() CLIP_DEF_COMMAND("stop", "stop sampling", adc_stop_callback) CLIP_DEF_COMMAND_END() CLIP_DEF_ROOT_COMMAND_END() @@ -131,11 +131,11 @@ CLIP_DEF_ROOT_COMMAND(g_gpio_cmd, "gpio", "control gpio", NULL) CLIP_DEF_COMMAND("pin", "get pin state", gpio_get_pin_callback) CLIP_DEF_WITH_ARGS() /* there will be 1 required argument in "gpio get pin" command */ CLIP_DEF_ARGUMENT("pin", "pin number", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND("reg", "get register value", gpio_get_reg_callback) CLIP_DEF_WITH_ARGS() /* there will be 1 required argument in "gpio get reg" command */ CLIP_DEF_ARGUMENT("address", "register address", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND_END() CLIP_DEF_COMMAND("set", "set methods", NULL) /* there will be 2 subcommands: pin, reg */ @@ -143,12 +143,12 @@ CLIP_DEF_ROOT_COMMAND(g_gpio_cmd, "gpio", "control gpio", NULL) /* there will be 2 required arguments in "gpio set pin" command */ CLIP_DEF_ARGUMENT("pin", "pin number", CLIP_ARG_TYPE_UINT) CLIP_DEF_ARGUMENT("state", "pin state", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND("reg", "set register value", gpio_set_reg_callback) CLIP_DEF_WITH_ARGS() /* there will be 2 required arguments in "gpio set reg" command */ CLIP_DEF_ARGUMENT("address", "register address", CLIP_ARG_TYPE_UINT) CLIP_DEF_ARGUMENT("value", "register value", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND_END() CLIP_DEF_ROOT_COMMAND_END() @@ -159,12 +159,12 @@ CLIP_DEF_ROOT_COMMAND(g_mem_cmd, "mem", "memory driver", NULL) /* there will be 2 required arguments in "mem write" command */ CLIP_DEF_ARGUMENT("address", "address to write", CLIP_ARG_TYPE_UINT) CLIP_DEF_ARGUMENT("data", "binary data to write", CLIP_ARG_TYPE_HEXARRAY) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND("read", "read data from memory", mem_read_callback) CLIP_DEF_WITH_ARGS() /* there will be 2 required arguments in "mem read" command */ CLIP_DEF_ARGUMENT("address", "address to read", CLIP_ARG_TYPE_UINT) CLIP_DEF_ARGUMENT("size", "number of bytes to read", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_ROOT_COMMAND_END() /* Definition of command: exit */ diff --git a/examples/BasicCLI/cli.c b/examples/BasicCLI/cli.c index 05c9814..85d04b8 100644 --- a/examples/BasicCLI/cli.c +++ b/examples/BasicCLI/cli.c @@ -27,16 +27,16 @@ SOFTWARE. CLIP_DEF_ROOT_COMMAND(g_cli_gpio_cmd, "gpio", "control gpio", NULL) CLIP_DEF_COMMAND("get", "get pin state", cli_gpio_get_callback) CLIP_DEF_WITH_ARGS() CLIP_DEF_ARGUMENT("pin", "pin number", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND("set", "set pin state", cli_gpio_set_callback) CLIP_DEF_WITH_ARGS() CLIP_DEF_ARGUMENT("pin", "pin number", CLIP_ARG_TYPE_UINT) CLIP_DEF_ARGUMENT("state", "pin state", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_ROOT_COMMAND_END() CLIP_DEF_ROOT_COMMAND(g_cli_echo_cmd, "echo", "echo command", cli_echo_callback) CLIP_DEF_WITH_ARGS() CLIP_DEF_ARGUMENT("text", "text to print", CLIP_ARG_TYPE_STRING) -CLIP_DEF_ROOT_COMMAND_END() +CLIP_DEF_ROOT_COMMAND_END_WITH_ARGS() CLIP_DEF_ROOT(g_cli_clip, NULL, cli_event_callback) CLIP_DEF_ADD_ROOT_COMMAND(&g_cli_gpio_cmd) diff --git a/examples/linux/src/adc.c b/examples/linux/src/adc.c index d6dc6b0..a9b71ba 100644 --- a/examples/linux/src/adc.c +++ b/examples/linux/src/adc.c @@ -62,11 +62,11 @@ CLIP_DEF_ROOT_COMMAND(g_adc_cmd, "adc", "control adc driver", NULL) CLIP_DEF_COMMAND("read", "read input", adc_read_callback) CLIP_DEF_WITH_ARGS() CLIP_DEF_ARGUMENT("channel", "channel number", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND("set", "set reference", adc_set_callback) CLIP_DEF_WITH_ARGS() CLIP_DEF_ARGUMENT("vref", "voltage reference", CLIP_ARG_TYPE_FLOAT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND("start", "start sampling", adc_start_callback) CLIP_DEF_COMMAND_END() CLIP_DEF_COMMAND("stop", "stop sampling", adc_stop_callback) CLIP_DEF_COMMAND_END() diff --git a/examples/linux/src/gpio.c b/examples/linux/src/gpio.c index 9099221..3e6b59c 100644 --- a/examples/linux/src/gpio.c +++ b/examples/linux/src/gpio.c @@ -65,23 +65,23 @@ CLIP_DEF_ROOT_COMMAND(g_gpio_cmd, "gpio", "control gpio", NULL) CLIP_DEF_COMMAND("get", "get methods", NULL) CLIP_DEF_COMMAND("pin", "get pin state", gpio_get_pin_callback) CLIP_DEF_WITH_ARGS() CLIP_DEF_ARGUMENT("pin", "pin number", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND("reg", "get register value", gpio_get_reg_callback) CLIP_DEF_WITH_ARGS() CLIP_DEF_ARGUMENT("address", "register address", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND_END() CLIP_DEF_COMMAND("set", "set methods", NULL) CLIP_DEF_COMMAND("pin", "set pin state", gpio_set_pin_callback) CLIP_DEF_WITH_ARGS() CLIP_DEF_ARGUMENT("pin", "pin number", CLIP_ARG_TYPE_UINT) CLIP_DEF_ARGUMENT("state", "pin state", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND("reg", "set register value", gpio_set_reg_callback) CLIP_DEF_WITH_ARGS() CLIP_DEF_ARGUMENT("address", "register address", CLIP_ARG_TYPE_UINT) CLIP_DEF_ARGUMENT("value", "register value", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND_END() diff --git a/examples/linux/src/mem.c b/examples/linux/src/mem.c index f9d305d..0394640 100644 --- a/examples/linux/src/mem.c +++ b/examples/linux/src/mem.c @@ -53,11 +53,11 @@ CLIP_DEF_ROOT_COMMAND(g_mem_cmd, "mem", "memory driver", NULL) CLIP_DEF_COMMAND("write", "write data to memory", mem_write_callback) CLIP_DEF_WITH_ARGS() CLIP_DEF_ARGUMENT("address", "address to write", CLIP_ARG_TYPE_UINT) CLIP_DEF_ARGUMENT("data", "binary data to write", CLIP_ARG_TYPE_HEXARRAY) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_COMMAND("read", "read data from memory", mem_read_callback) CLIP_DEF_WITH_ARGS() CLIP_DEF_ARGUMENT("address", "address to read", CLIP_ARG_TYPE_UINT) CLIP_DEF_ARGUMENT("size", "number of bytes to read", CLIP_ARG_TYPE_UINT) - CLIP_DEF_COMMAND_END() + CLIP_DEF_COMMAND_END_WITH_ARGS() CLIP_DEF_ROOT_COMMAND_END() diff --git a/src/clip_cmd_call.c b/src/clip_cmd_call.c index f48ef0e..7c649e9 100644 --- a/src/clip_cmd_call.c +++ b/src/clip_cmd_call.c @@ -51,7 +51,6 @@ void clip_cmd_call_command_callback(const struct clip *self, const struct clip_c av->val_str = arg; const struct clip_arg *ca = NULL; - char *end_arg = NULL; if (no_more_required_args == false && cmd->args != NULL) { ca = cmd->args[argc]; if (ca != NULL) { diff --git a/src/clip_defs.h b/src/clip_defs.h index 75d1de8..ac4182b 100644 --- a/src/clip_defs.h +++ b/src/clip_defs.h @@ -48,11 +48,18 @@ const struct clip_command var_name = {\ _CLIP_DEF_COMMAND(cmd_name, cmd_description, callback_func)\ ///< public macro for finishing root command definition -#define CLIP_DEF_ROOT_COMMAND_END()\ +#define CLIP_DEF_ROOT_COMMAND_END_WITH_ARGS()\ NULL,\ }\ };\ +///< public macro for finishing root command without args definition +#define CLIP_DEF_ROOT_COMMAND_END()\ + NULL,\ + },\ + .args = NULL\ +};\ + ///< public macro for defining command #define CLIP_DEF_COMMAND(cmd_name, cmd_description, callback_func)\ &(const struct clip_command) {\ @@ -67,11 +74,18 @@ const struct clip_command var_name = {\ },\ ///< public macro for finishing command definition -#define CLIP_DEF_COMMAND_END()\ +#define CLIP_DEF_COMMAND_END_WITH_ARGS()\ NULL,\ }\ },\ +///< public macro for finishing command without args definition +#define CLIP_DEF_COMMAND_END()\ + NULL,\ + },\ + .args = NULL\ + },\ + ///< public macro for defining arguments for subcommand #define CLIP_DEF_WITH_ARGS()\ NULL,\ diff --git a/src/clip_utils_arg.c b/src/clip_utils_arg.c index fff4dbe..2b2fb79 100644 --- a/src/clip_utils_arg.c +++ b/src/clip_utils_arg.c @@ -32,7 +32,6 @@ char* clip_utils_arg_get_first(char **arg, char *cmd_line) CLIP_CONFIG_ASSERT(arg != NULL); CLIP_CONFIG_ASSERT(cmd_line != NULL); - int state = 0; int escape = 0; int quotemark = 0; size_t arg_pos = 0;