1
0
mirror of https://github.com/NevermindZZT/letter-shell.git synced 2025-01-21 10:02:54 +08:00

优化 代码结构

This commit is contained in:
Letter 2020-08-01 13:42:39 +08:00
parent a4a8f98f7d
commit 55cb066db8
3 changed files with 24 additions and 42 deletions

View File

@ -14,10 +14,6 @@
#include "shell_cfg.h" #include "shell_cfg.h"
#if SHELL_USING_COMPANION == 1
#include "shell_companion.h"
#endif
#define SHELL_VERSION "3.0.3" /**< 版本号 */ #define SHELL_VERSION "3.0.3" /**< 版本号 */
@ -400,5 +396,24 @@ void shellHandler(Shell *shell, char data);
void shellTask(void *param); void shellTask(void *param);
int shellRun(Shell *shell, const char *cmd); int shellRun(Shell *shell, const char *cmd);
#if SHELL_USING_COMPANION == 1
/**
* @brief shell伴生对象定义
*/
typedef struct shell_companion_object
{
int id; /**< 伴生对象ID */
void *obj; /**< 伴生对象 */
struct shell_companion_object *next; /**< 下一个伴生对象 */
} ShellCompanionObj;
signed char shellCompanionAdd(Shell *shell, int id, void *object);
signed char shellCompanionDel(Shell *shell, int id);
void *shellCompanionGet(Shell *shell, int id);
#endif
#endif #endif

View File

@ -8,10 +8,9 @@
* @copyright (c) 2020 Letter * @copyright (c) 2020 Letter
* *
*/ */
#include "shell_companion.h"
#include "shell.h" #include "shell.h"
#if SHELL_USING_COMPANION == 1
/** /**
* @brief shell添加伴生对象 * @brief shell添加伴生对象
* *
@ -20,7 +19,7 @@
* @param object * @param object
* @return signed char 0 -1 * @return signed char 0 -1
*/ */
signed char shellCompanionAdd(struct shell_def *shell, int id, void *object) signed char shellCompanionAdd(Shell *shell, int id, void *object)
{ {
ShellCompanionObj *companions = shell->info.companions; ShellCompanionObj *companions = shell->info.companions;
ShellCompanionObj *node = SHELL_MALLOC(sizeof(ShellCompanionObj)); ShellCompanionObj *node = SHELL_MALLOC(sizeof(ShellCompanionObj));
@ -39,7 +38,7 @@ signed char shellCompanionAdd(struct shell_def *shell, int id, void *object)
* @param id ID * @param id ID
* @return signed char 0 -1 * @return signed char 0 -1
*/ */
signed char shellCompanionDel(struct shell_def *shell, int id) signed char shellCompanionDel(Shell *shell, int id)
{ {
ShellCompanionObj *companions = shell->info.companions; ShellCompanionObj *companions = shell->info.companions;
ShellCompanionObj *front = companions; ShellCompanionObj *front = companions;
@ -71,7 +70,7 @@ signed char shellCompanionDel(struct shell_def *shell, int id)
* @param id ID * @param id ID
* @return void* NULL * @return void* NULL
*/ */
void *shellCompanionGet(struct shell_def *shell, int id) void *shellCompanionGet(Shell *shell, int id)
{ {
SHELL_ASSERT(shell, return (void *)0); SHELL_ASSERT(shell, return (void *)0);
ShellCompanionObj *companions = shell->info.companions; ShellCompanionObj *companions = shell->info.companions;
@ -85,3 +84,4 @@ void *shellCompanionGet(struct shell_def *shell, int id)
} }
return (void *)0; return (void *)0;
} }
#endif /** SHELL_USING_COMPANION == 1 */

View File

@ -1,33 +0,0 @@
/**
* @file shell_companion.h
* @author Letter (nevermindzzt@gmail.com)
* @brief shell companion object support
* @version 3.0.3
* @date 2020-07-22
*
* @copyright (c) 2020 Letter
*
*/
#ifndef __SHELL_COMPANION_H__
#define __SHELL_COMPANION_H__
#include "shell_cfg.h"
#include "shell.h"
/**
* @brief shell伴生对象定义
*/
typedef struct shell_companion_object
{
int id; /**< 伴生对象ID */
void *obj; /**< 伴生对象 */
struct shell_companion_object *next; /**< 下一个伴生对象 */
} ShellCompanionObj;
signed char shellCompanionAdd(struct shell_def *shell, int id, void *object);
signed char shellCompanionDel(struct shell_def *shell, int id);
void *shellCompanionGet(struct shell_def *shell, int id);
#endif