mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-11 05:24:44 -04:00
Use string instead of cstring
This commit is contained in:
parent
33818dbc51
commit
bce0d84f98
@ -7,10 +7,11 @@
|
|||||||
|
|
||||||
#include <print.hpp>
|
#include <print.hpp>
|
||||||
#include <system.hpp>
|
#include <system.hpp>
|
||||||
#include <cstring.hpp>
|
#include <string.hpp>
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
char input_buffer[64];
|
char input_buffer[64];
|
||||||
|
std::string current_input;
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
print("thor> ");
|
print("thor> ");
|
||||||
@ -18,27 +19,28 @@ int main(){
|
|||||||
auto c = read_input(input_buffer, 63);
|
auto c = read_input(input_buffer, 63);
|
||||||
|
|
||||||
if(input_buffer[c-1] == '\n'){
|
if(input_buffer[c-1] == '\n'){
|
||||||
if(c == 1){
|
|
||||||
print_line();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
input_buffer[c-1] = '\0';
|
input_buffer[c-1] = '\0';
|
||||||
|
|
||||||
if(str_equals(input_buffer, "exit")){
|
current_input = input_buffer;
|
||||||
|
|
||||||
|
if(current_input == "exit"){
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if(str_equals(input_buffer, "long")){
|
} else if(current_input == "long"){
|
||||||
//TODO Remove this function when exec system is complete
|
//TODO Remove this function when exec system is complete
|
||||||
exec_and_wait("long");
|
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
|
//TODO Once better infrastrucure, parse command line and sleep the
|
||||||
//correct number of milliseconds
|
//correct number of milliseconds
|
||||||
sleep_ms(5000);
|
sleep_ms(5000);
|
||||||
} else {
|
} else {
|
||||||
print_line("Unknown command");
|
print_line("Unknown command");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current_input.clear();
|
||||||
} else {
|
} else {
|
||||||
//TODO Once in good shape, just append to current input buffer
|
input_buffer[c] = '\0';
|
||||||
|
|
||||||
|
current_input += input_buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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
|
|
@ -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;
|
|
||||||
}
|
|
@ -142,6 +142,34 @@ public:
|
|||||||
return *this;
|
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
|
//Accessors
|
||||||
|
|
||||||
size_t size() const {
|
size_t size() const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user