/** * \brief Command input handler. * * Process the input, calling the requested command (if found). * * \param input Text line to be processed (ASCIIZ) * * \return true if everything is OK, false in case of errors */ bool parser_process_line(const char* input) { const struct CmdTemplate *cmdp; parms args[CONFIG_PARSER_MAX_ARGS]; cmdp = parser_get_cmd_template(input); if (!cmdp) return false; if (!parser_get_cmd_arguments(input, cmdp, args)) return false; if (!parser_execute_cmd(cmdp, args)) return false; return true; }
static void protocol_parse(KFile *fd, const char *buf) { const struct CmdTemplate *templ; /* Command check. */ templ = parser_get_cmd_template(buf); if (!templ) { kfile_print(fd, "-1 Invalid command.\r\n"); protocol_prompt(fd); return; } parms args[PARSER_MAX_ARGS]; /* Args Check. TODO: Handle different case. see doc/PROTOCOL . */ if (!parser_get_cmd_arguments(buf, templ, args)) { kfile_print(fd, "-2 Invalid arguments.\r\n"); protocol_prompt(fd); return; } /* Execute. */ if(!parser_execute_cmd(templ, args)) { NAK(fd, "Error in executing command."); } if (!protocol_reply(fd, templ, args)) { NAK(fd, "Invalid return format."); } protocol_prompt(fd); return; }