summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-05-05 18:04:02 +0200
committerNao Pross <naopross@thearcway.org>2018-05-05 18:04:02 +0200
commit54c64b887fb9af6cff1203e085c0464c25743cb5 (patch)
treea3aaf377cf5ac77bd6440b518e9fa9dcc6c68f72
parentAdd command selection code, note: split() does't work yet (diff)
downloadSAMLiquidSmoke-54c64b887fb9af6cff1203e085c0464c25743cb5.tar.gz
SAMLiquidSmoke-54c64b887fb9af6cff1203e085c0464c25743cb5.zip
Fix split()
-rw-r--r--main.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/main.cpp b/main.cpp
index fec1ba0..29263cd 100644
--- a/main.cpp
+++ b/main.cpp
@@ -37,7 +37,7 @@ std::vector<std::string> split(const std::string& str, const char sep)
size_t next = 0;
while ((next = str.find(sep, last)) != std::string::npos) {
- v.push_back(str.substr(next, next +1));
+ v.push_back(str.substr(last, next-last));
last = next + 1;
}
@@ -87,19 +87,16 @@ int main(int argc, char** argv)
// write prompt
uart::write<1>("> ");
-
- while (uart::rx_buffer<1>().empty());
+
do {
- input += uart::read_wait<1>();
- } while (uart::rx_buffer<1>().front() != '\r');
- // remove '\r' from the RX buffer
- uart::rx_buffer<1>().pop();
+ input += uart::read_wait<1>();
+ } while (input.back() != '\r');
#ifdef DEBUG
uart::write<1>("\n\rinput: ");
uart::print<1>(input);
#endif
-
+
// remove weird symbols
strip(input);
@@ -107,8 +104,9 @@ int main(int argc, char** argv)
const std::vector<std::string> command = split(input, ' ');
#ifdef DEBUG
- for (const std::string &s : command) {
- uart::print<1>(s);
+ uart::print<1>("parsed commmands:");
+ for (int i = 0; i < command.size(); i++) {
+ uart::print<1>(command[i]);
}
#endif