Commit cd36d4bb authored by Nelso Jost's avatar Nelso Jost

FIX added double quoted arg parsing

parent cf89e850
...@@ -30,12 +30,20 @@ ...@@ -30,12 +30,20 @@
#define PIN_NOTIFY_ACTIVE D4 #define PIN_NOTIFY_ACTIVE D4
#define CMD_REPL_ARGTEST {\
"argtest", REPL_ARGTEST, "argtest <arg1> <arg2>", \
"Just test get_arg() with quotes."}
void REPL_ARGTEST(REPL * repl);
REPL_COMMAND commands[] =\ REPL_COMMAND commands[] =\
{ {
ALLCMD_REPL_GPIO, ALLCMD_REPL_GPIO,
ALLCMD_REPL_SDCARD, ALLCMD_REPL_SDCARD,
ALLCMD_REPL_WIFI, ALLCMD_REPL_WIFI,
ALLCMD_REPL_METEOROLOGGER, ALLCMD_REPL_METEOROLOGGER,
CMD_REPL_ARGTEST,
{NULL} {NULL}
}; };
REPL repl(commands); REPL repl(commands);
...@@ -90,3 +98,10 @@ void REPL_SHOWCONFIG(REPL * repl) ...@@ -90,3 +98,10 @@ void REPL_SHOWCONFIG(REPL * repl)
{ {
meteorologger.print_config(); meteorologger.print_config();
} }
void REPL_ARGTEST(REPL * repl)
{
repl->log("\narg1:" + repl->get_arg(1));
repl->log("\narg2:" + repl->get_arg(2));
}
...@@ -228,15 +228,28 @@ String REPL::get_arg(int index) ...@@ -228,15 +228,28 @@ String REPL::get_arg(int index)
String arg=""; String arg="";
int count=-1; int count=-1;
bool found=false; bool found=false;
bool quotes=false;
char c;
for (int i=0; i < this->_command_buffer.length(); i++) for (int i=0; i < this->_command_buffer.length(); i++)
{ {
if (this->_command_buffer[i] != ' ') c = this->_command_buffer[i];
if (c != ' ')
{ {
if (c == '\"')
{
quotes = !quotes;
continue;
}
found = true; found = true;
arg += this->_command_buffer[i]; arg += c;
} }
else if (found == true) else if (found == true)
{ {
if (quotes)
{
arg += c;
continue;
}
count += 1; count += 1;
if (count == index) return arg; if (count == index) return arg;
found = false; found = false;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
class REPL; class REPL;
typedef struct typedef struct
{ {
const char *name; const char *name;
...@@ -19,7 +20,6 @@ typedef struct ...@@ -19,7 +20,6 @@ typedef struct
} REPL_COMMAND; } REPL_COMMAND;
class REPL class REPL
{ {
public: public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment