diff --git a/firmware/controllers/core/logic_expression.cpp b/firmware/controllers/core/logic_expression.cpp index bd83110e72..940cd3e449 100644 --- a/firmware/controllers/core/logic_expression.cpp +++ b/firmware/controllers/core/logic_expression.cpp @@ -131,3 +131,23 @@ void LEElementPool::reset() { LEElement *LEElementPool::next() { return &pool[index++]; } + +const char *processToken(const char *line, char *buffer) { + while (line[0] != 0 && line[0] == ' ') { + line++; + } + if (line[0] == 0) { + return NULL; + } + int tokenLen = indexOf(line, ' '); + if (tokenLen == -1) { + // no space - the whole remaining line is the token + strcpy(buffer, line); + return line + strlen(buffer); + } + strncpy(buffer, line, tokenLen); + buffer[tokenLen] = 0; + line += tokenLen; + return line; +} + diff --git a/firmware/controllers/core/logic_expression.h b/firmware/controllers/core/logic_expression.h index 4f91667548..04865e7a52 100644 --- a/firmware/controllers/core/logic_expression.h +++ b/firmware/controllers/core/logic_expression.h @@ -72,4 +72,6 @@ private: FLStack stack; }; +const char *processToken(const char *line, char *buffer); + #endif /* LOGIC_EXPRESSION_H_ */ diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 38f9b4ad5a..ac4d3f8d5f 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -241,5 +241,5 @@ void firmwareError(const char *fmt, ...) { } int getRusEfiVersion(void) { - return 20141003; + return 20141004; } diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index a7e5c7f6c6..3185994289 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -132,7 +132,7 @@ int main(void) { testFLStack(); // resizeMap(); - printf("Success 20131003\r\n"); + printf("Success 20131004\r\n"); return EXIT_SUCCESS; } diff --git a/unit_tests/test_logic_expression.cpp b/unit_tests/test_logic_expression.cpp index 87f3348062..5ffdbb44ed 100644 --- a/unit_tests/test_logic_expression.cpp +++ b/unit_tests/test_logic_expression.cpp @@ -10,10 +10,25 @@ #include "main.h" #include "test_logic_expression.h" #include "logic_expression.h" +#include "cli_registry.h" void testLogicExpressions(void) { printf("*************************************************** testLogicExpressions\r\n"); + char buffer[64]; + + const char *ptr; + ptr = processToken(" hello ", buffer); + assertTrue(strEqual("hello", buffer)); + + ptr = processToken("hello", buffer); + assertTrue(strEqual("hello", buffer)); + + ptr = processToken(" hello world ", buffer); + assertTrue(strEqual("hello", buffer)); + ptr = processToken(ptr, buffer); + assertTrue(strEqual("world", buffer)); + LECalculator c; LEElement value1; @@ -22,7 +37,6 @@ void testLogicExpressions(void) { assertEqualsM("123", 123.0, c.getValue()); - LEElement value2; value2.init(LE_NUMERIC_VALUE, 321.0); c.add(&value2); @@ -61,7 +75,6 @@ void testLogicExpressions(void) { e = pool.next(); e->init(LE_OPERATOR_OR); - /** * fan = (not fan && coolant > 90) OR (fan && coolant > 85) * fan = fan NOT coolant 90 AND more fan coolant 85 more AND OR