From 5a00f22e31b8ec640daa48bded9b616ffd2320b4 Mon Sep 17 00:00:00 2001 From: prozessorkern Date: Sun, 22 Mar 2020 20:07:30 +0100 Subject: [PATCH] added the help command variable to the instance structure to get independant commands for each instance fix #42 --- api/shellmatta.h | 1 + src/shellmatta.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/shellmatta.h b/api/shellmatta.h index 55ef256..804f2c9 100644 --- a/api/shellmatta.h +++ b/api/shellmatta.h @@ -140,6 +140,7 @@ typedef struct const char *prompt; /**< prompt is printed after every command */ shellmatta_mode_t mode; /**< mode of the shell */ shellmatta_write_t write; /**< pointer to write function */ + shellmatta_cmd_t helpCmd; /**< help command structure */ shellmatta_cmd_t *cmdList; /**< pointer to the first command */ bool cmdListIsConst; /**< true if the #cmdList was passed during initialization */ diff --git a/src/shellmatta.c b/src/shellmatta.c index b474c91..d6a2d1d 100644 --- a/src/shellmatta.c +++ b/src/shellmatta.c @@ -93,12 +93,15 @@ shellmatta_retCode_t shellmatta_doInit( inst->hereDelimiterIdx = 0u; inst->hereLength = 0u; inst->mode = SHELLMATTA_MODE_INSERT; - inst->cmdList = &helpCmd; + inst->cmdList = &(inst->helpCmd); inst->cmdListIsConst = false; + /*! -# copy the help command structure to this instance */ + memcpy(&(inst->helpCmd), &helpCmd, sizeof(shellmatta_cmd_t)); + if(NULL != cmdList) { - helpCmd.next = (shellmatta_cmd_t *) cmdList; + inst->helpCmd.next = (shellmatta_cmd_t *) cmdList; inst->cmdListIsConst = true; }