projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Remove syslog from nightly test.
[bertos.git]
/
bertos
/
mware
/
parser.c
diff --git
a/bertos/mware/parser.c
b/bertos/mware/parser.c
index fe6c1352714332f84da30430664fd8e90dce007d..e08dd8b66f80a2dba0c1aff5484f705215a17f97 100644
(file)
--- a/
bertos/mware/parser.c
+++ b/
bertos/mware/parser.c
@@
-55,6
+55,8
@@
#include "parser.h"
#include "parser.h"
+#include "cfg/cfg_parser.h"
+
#include <io/kfile.h>
#include <struct/hashtable.h>
#include <io/kfile.h>
#include <struct/hashtable.h>
@@
-87,17
+89,31
@@
DECLARE_HASHTABLE_STATIC(commands, CONFIG_MAX_COMMANDS_NUMBER, get_key_from_comm
* \return True if a word was extracted, false if we got to the end
* of the string without extracting any word.
*/
* \return True if a word was extracted, false if we got to the end
* of the string without extracting any word.
*/
-
static
bool get_word(const char **begin, const char **end)
+bool get_word(const char **begin, const char **end)
{
const char *cur = *end;
{
const char *cur = *end;
+ bool open_quote = false;
while ((*cur == ' ' || *cur == '\t') && *cur)
++cur;
while ((*cur == ' ' || *cur == '\t') && *cur)
++cur;
+ if (*cur == '"')
+ open_quote = true;
+
*begin = cur;
*begin = cur;
- while ((*cur != ' ' && *cur != '\t') && *cur)
+ if (open_quote)
+ {
++cur;
++cur;
+ while (*cur != '"' && *cur)
+ ++cur;
+ if (*cur != '"')
+ return false;
+ ++cur;
+ }
+ else
+ while ((*cur != ' ' && *cur != '\t') && *cur)
+ ++cur;
*end = cur;
*end = cur;
@@
-135,7
+151,15
@@
static bool parseArgs(const char *fmt, const char *input, parms argv[])
break;
case 's':
break;
case 's':
- (*argv++).s = begin;
+ (*argv).s.p = begin;
+ (*argv).s.sz = end - begin;
+ /* Remove the quotes from argument */
+ if (*begin == '"' && *(end - 1) == '"')
+ {
+ (*argv).s.p += 1;
+ (*argv).s.sz -= 2;
+ }
+ argv++;
break;
default:
break;
default:
@@
-206,7
+230,7
@@
bool parser_get_cmd_id(const char* line, unsigned long* ID)
* in a given text line without parsing all the parameters and
* executing it.
*
* in a given text line without parsing all the parameters and
* executing it.
*
- * \param
line
Text line to be processed (ASCIIZ)
+ * \param
input
Text line to be processed (ASCIIZ)
*
* \return The command template associated with the command contained
* in the line, or NULL if the command is invalid.
*
* \return The command template associated with the command contained
* in the line, or NULL if the command is invalid.
@@
-250,8
+274,8
@@
static const char *skip_to_params(const char *input, const struct CmdTemplate *c
* The first argument will always be the command name, so the actual arguments
* will start at index 1.
*
* The first argument will always be the command name, so the actual arguments
* will start at index 1.
*
- * \param
line
Text line to be processed (ASCIIZ)
- * \param
templ
Command template for this line
+ * \param
input
Text line to be processed (ASCIIZ)
+ * \param
cmdp
Command template for this line
* \param args Will contain the extracted parameters
*
* \return True if everything OK, false in case of parsing error.
* \param args Will contain the extracted parameters
*
* \return True if everything OK, false in case of parsing error.
@@
-262,7
+286,7
@@
bool parser_get_cmd_arguments(const char* input, const struct CmdTemplate* cmdp,
if (!input)
return false;
if (!input)
return false;
- args[0].s = cmdp->name;
+ args[0].s
.p
= cmdp->name;
if (!parseArgs(cmdp->arg_fmt, input, args + 1))
return false;
if (!parseArgs(cmdp->arg_fmt, input, args + 1))
return false;
@@
-281,7
+305,7
@@
static const void* get_key_from_command(const void* cmd, uint8_t* length)
*
* Process the input, calling the requested command (if found).
*
*
* Process the input, calling the requested command (if found).
*
- * \param
line
Text line to be processed (ASCIIZ)
+ * \param
input
Text line to be processed (ASCIIZ)
*
* \return true if everything is OK, false in case of errors
*/
*
* \return true if everything is OK, false in case of errors
*/
@@
-307,10
+331,11
@@
bool parser_process_line(const char* input)
* Register a new command into the parser
*
* \param cmd Command template describing the command
* Register a new command into the parser
*
* \param cmd Command template describing the command
+ * \return true if registration was successful, false otherwise
*/
*/
-
void
parser_register_cmd(const struct CmdTemplate* cmd)
+
bool
parser_register_cmd(const struct CmdTemplate* cmd)
{
{
- ht_insert(&commands, cmd);
+
return
ht_insert(&commands, cmd);
}
void parser_init(void)
}
void parser_init(void)