Skip to content

Commit

Permalink
FINSH: 优化MSH宏定义
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloByeAll committed Nov 12, 2023
1 parent df0d8b4 commit 5717166
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions components/finsh/finsh.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,15 @@ typedef long (*syscall_func)(void);
#define _MSH_FUNCTION_CMD2(a0, a1) \
MSH_FUNCTION_EXPORT_CMD(a0, a0, a1, 0)

#define _MSH_FUNCTION_CMD3_OPT(a0, a1, a2) \
#define _MSH_FUNCTION_CMD2_OPT(a0, a1, a2) \
MSH_FUNCTION_EXPORT_CMD(a0, a0, a1, a0##_msh_options)

#define _MSH_FUNCTION_CMD3_NO_OPT(a0, a1, a2) \
MSH_FUNCTION_EXPORT_CMD(a0, a0, a1, 0)

#define _MSH_FUNCTION_EXPORT_CMD3(a0, a1, a2) \
MSH_FUNCTION_EXPORT_CMD(a0, a1, a2, 0)

#define _MSH_FUNCTION_EXPORT_CMD4_OPT(a0, a1, a2, a3) \
#define _MSH_FUNCTION_EXPORT_CMD3_OPT(a0, a1, a2, a3) \
MSH_FUNCTION_EXPORT_CMD(a0, a1, a2, a0##_msh_options)

#define _MSH_FUNCTION_EXPORT_CMD4_NO_OPT(a0, a1, a2, a3) \
MSH_FUNCTION_EXPORT_CMD(a0, a1, a2, 0)

/**
* @ingroup finsh
Expand Down Expand Up @@ -135,15 +130,9 @@ typedef long (*syscall_func)(void);
* @param opt This is an option, enter any content to enable option completion
*/
/* MSH_CMD_EXPORT(command, desc) or MSH_CMD_EXPORT(command, desc, opt) */
#ifdef FINSH_USING_OPTION_COMPLETION
#define MSH_CMD_EXPORT(...) \
__MSH_GET_MACRO(__VA_ARGS__, _MSH_FUNCTION_CMD3_OPT, \
__MSH_GET_MACRO(__VA_ARGS__, _MSH_FUNCTION_CMD2_OPT, \
_MSH_FUNCTION_CMD2)(__VA_ARGS__)
#else
#define MSH_CMD_EXPORT(...) \
__MSH_GET_MACRO(__VA_ARGS__, _MSH_FUNCTION_CMD3_NO_OPT, \
_MSH_FUNCTION_CMD2)(__VA_ARGS__)
#endif /* FINSH_USING_OPTION_COMPLETION */

/**
* @ingroup msh
Expand All @@ -157,15 +146,9 @@ typedef long (*syscall_func)(void);
*/
/* #define MSH_CMD_EXPORT_ALIAS(command, alias, desc) or
#define MSH_CMD_EXPORT_ALIAS(command, alias, desc, opt) */
#ifdef FINSH_USING_OPTION_COMPLETION
#define MSH_CMD_EXPORT_ALIAS(...) \
__MSH_GET_EXPORT_MACRO(__VA_ARGS__, _MSH_FUNCTION_EXPORT_CMD4_OPT, \
_MSH_FUNCTION_EXPORT_CMD3)(__VA_ARGS__)
#else
#define MSH_CMD_EXPORT_ALIAS(...) \
__MSH_GET_EXPORT_MACRO(__VA_ARGS__, _MSH_FUNCTION_EXPORT_CMD4_NO_OPT, \
__MSH_GET_EXPORT_MACRO(__VA_ARGS__, _MSH_FUNCTION_EXPORT_CMD3_OPT, \
_MSH_FUNCTION_EXPORT_CMD3)(__VA_ARGS__)
#endif /* FINSH_USING_OPTION_COMPLETION */

/* system call table */
struct finsh_syscall
Expand All @@ -192,8 +175,8 @@ struct finsh_syscall_item
typedef struct msh_cmd_opt
{
rt_uint32_t id;
const char *name;
const char *des;
const char *name;
const char *des;
} msh_cmd_opt_t;

#define CMD_OPTIONS_STATEMENT(command) static struct msh_cmd_opt command##_msh_options[];
Expand All @@ -211,6 +194,8 @@ int msh_cmd_opt_id_get(int argc, char *argv[], void *options);
#define CMD_OPTIONS_NODE_START(command)
#define CMD_OPTIONS_NODE(_id, _name, _des)
#define CMD_OPTIONS_NODE_END
#define MSH_OPT_ID_GET(fun) ((int)(-1UL))
#define MSH_OPT_DUMP(fun) do{}while(0)
#endif

extern struct finsh_syscall_item *global_syscall_list;
Expand Down

0 comments on commit 5717166

Please sign in to comment.