Browse Source

Merge branch '#10_minimal_configuration_without_printf' of shimatta/shellmatta into develop

shimatta 5 years ago
parent
commit
ad7d4c39c4
2 changed files with 41 additions and 11 deletions
  1. 5 0
      api/shellmatta.h
  2. 36 11
      src/shellmatta.c

+ 5 - 0
api/shellmatta.h

@@ -126,9 +126,14 @@ shellmatta_retCode_t shellmatta_addCmd( shellmatta_handle_t handle,
 shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
                                             char                *data,
                                             uint32_t            size);
+shellmatta_retCode_t shellmatta_write(  shellmatta_handle_t handle,
+                                        char                *data,
+                                        uint32_t            length);
+#ifndef SHELLMATTA_STRIP_PRINTF
 shellmatta_retCode_t shellmatta_printf( shellmatta_handle_t handle,
                                         const char          *fmt,
                                         ...);
+#endif
 
 #endif
 

+ 36 - 11
src/shellmatta.c

@@ -579,7 +579,8 @@ static void terminateInput(shellmatta_instance_t *inst)
 {
     inst->inputCount    = 0u;
     inst->cursor        = 0u;
-    shellmatta_printf(inst, "\r\n%s", inst->prompt);
+    inst->write("\r\n", 2u);
+    inst->write(inst->prompt, strlen(inst->prompt));
 }
 
 /**
@@ -773,16 +774,20 @@ static shellmatta_retCode_t helpCmdFct(shellmatta_handle_t handle, const char *a
         cmdAliasLen  = strlen(cmd->cmdAlias);
         cmdHelpLen   = strlen(cmd->helpText);
 
-        shellmatta_printf(handle, "%s  ", cmd->cmd);
-        tabCnt = (maxCmdLen - cmdLen);
+        inst->write(cmd->cmd, strlen(cmd->cmd));
+        tabCnt = (maxCmdLen - cmdLen) + 2u;
         SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt, inst->write);
-        shellmatta_printf(handle, "%s  ", cmd->cmdAlias);
-        tabCnt = (maxCmdAliasLen - cmdAliasLen);
+
+        inst->write(cmd->cmdAlias, strlen(cmd->cmdAlias));
+        tabCnt = (maxCmdAliasLen - cmdAliasLen) + 2u;
         SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt, inst->write);
-        shellmatta_printf(handle, "%s  ", cmd->helpText);
-        tabCnt = (maxCmdHelpLen - cmdHelpLen);
+
+        inst->write(cmd->helpText, strlen(cmd->helpText));
+        tabCnt = (maxCmdHelpLen - cmdHelpLen) + 2u;
         SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt, inst->write);
-        shellmatta_printf(handle, "%s\r\n", cmd->usageText);
+
+        inst->write(cmd->usageText, strlen(cmd->usageText));
+        inst->write("\r\n", 2u);
 
         cmd = cmd->next;
     }
@@ -1010,9 +1015,9 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t     handle,
                 if ((cmdExecuted == 0u) && (inst->inputCount > 0))
                 {
                     inst->buffer[inst->inputCount] = '\0';
-                    shellmatta_printf(  inst,
-                                        "\r\nCommand: %s not found",
-                                        inst->buffer);
+                    inst->write("\r\nCommand: ", 11u);
+                    inst->write(inst->buffer, inst->inputCount);
+                    inst->write(" not found", 10u);
                 }
                 terminateInput(inst);
             }
@@ -1069,6 +1074,25 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t     handle,
     return ret;
 }
 
+shellmatta_retCode_t shellmatta_write(  shellmatta_handle_t handle,
+                                        char                *data,
+                                        uint32_t            length)
+{
+    shellmatta_retCode_t    ret = SHELLMATTA_USE_FAULT;
+    shellmatta_instance_t   *inst = (shellmatta_instance_t*)handle;
+
+    /** -# check parameters for plausibility  */
+    if(     (NULL               != inst)
+        &&  (SHELLMATTA_MAGIC   == inst->magic))
+    {
+        ret = inst->write(data, length);
+    }
+
+    return ret;
+}
+
+#ifndef SHELLMATTA_STRIP_PRINTF
+
 /**
  * @brief       printf like function to print output to the instances output
  * @param[in]   handle  shellmatta instance handle
@@ -1110,6 +1134,7 @@ shellmatta_retCode_t shellmatta_printf( shellmatta_handle_t handle,
     }
     return ret;
 }
+#endif
 
 /** @} */
 /** @} */