diff --git a/programs/tsh/src/main.cpp b/programs/tsh/src/main.cpp index 05fc6deb..adf5973e 100644 --- a/programs/tsh/src/main.cpp +++ b/programs/tsh/src/main.cpp @@ -7,10 +7,11 @@ #include #include -#include +#include int main(){ char input_buffer[64]; + std::string current_input; while(true){ print("thor> "); @@ -18,27 +19,28 @@ int main(){ auto c = read_input(input_buffer, 63); if(input_buffer[c-1] == '\n'){ - if(c == 1){ - print_line(); - continue; - } - input_buffer[c-1] = '\0'; - if(str_equals(input_buffer, "exit")){ + current_input = input_buffer; + + if(current_input == "exit"){ exit(0); - } else if(str_equals(input_buffer, "long")){ + } else if(current_input == "long"){ //TODO Remove this function when exec system is complete exec_and_wait("long"); - } else if(str_equals(input_buffer, "sleep")){ + } else if(current_input == "sleep"){ //TODO Once better infrastrucure, parse command line and sleep the //correct number of milliseconds sleep_ms(5000); } else { print_line("Unknown command"); } + + current_input.clear(); } else { - //TODO Once in good shape, just append to current input buffer + input_buffer[c] = '\0'; + + current_input += input_buffer; } } } \ No newline at end of file diff --git a/tlib/include/cstring.hpp b/tlib/include/cstring.hpp deleted file mode 100644 index 8586b570..00000000 --- a/tlib/include/cstring.hpp +++ /dev/null @@ -1,17 +0,0 @@ -//======================================================================= -// Copyright Baptiste Wicht 2013-2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -//======================================================================= - -#ifndef USERLIB_STRING_H -#define USERLIB_STRING_H - -//TODO Once the shell use std::string, remove this file and its source file -//equivalent - -int str_compare(const char *s1, const char *s2); -bool str_equals(const char* s1, const char* s2); - -#endif diff --git a/tlib/src/cstring.cpp b/tlib/src/cstring.cpp deleted file mode 100644 index c0a09991..00000000 --- a/tlib/src/cstring.cpp +++ /dev/null @@ -1,37 +0,0 @@ -//======================================================================= -// Copyright Baptiste Wicht 2013-2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -//======================================================================= - -#include "string.hpp" - -int str_compare(const char *s1, const char *s2){ - while (*s1 != '\0') { - if (*s2 == '\0'){ - return 1; - } - - if (*s2 > *s1){ - return -1; - } - - if (*s1 > *s2){ - return 1; - } - - s1++; - s2++; - } - - if (*s2 != '\0'){ - return -1; - } - - return 0; -} - -bool str_equals(const char* s1, const char* s2){ - return str_compare(s1, s2) == 0; -} diff --git a/tstl/include/string.hpp b/tstl/include/string.hpp index 59245b76..5da2594d 100644 --- a/tstl/include/string.hpp +++ b/tstl/include/string.hpp @@ -142,6 +142,34 @@ public: return *this; } + basic_string& operator+=(const char* rhs){ + auto len = str_len(rhs); + if(!_data || _capacity <= _size + len){ + _capacity = _capacity ? _capacity * 2 : 1; + + if(_capacity < _size + len){ + _capacity = _size + len + 1; + } + + auto new_data = new CharT[_capacity]; + + if(_data){ + std::copy_n(new_data, _data, _size); + delete[] _data; + } + + _data = new_data; + } + + std::copy_n(_data + _size, rhs, len); + + _size += len; + + _data[_size] = '\0'; + + return *this; + } + //Accessors size_t size() const {