File size: 2,507 Bytes
d1be154 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | #include <ot/shell/shell.hpp>
namespace ot {
// Procedure: echo
void Shell::_echo() {
if(::system(_line.data()) == -1) {
_es << strerror(errno) << '\n';
}
}
// ------------------------------------------------------------------------------------------------
// Procedure: which
void Shell::_which() {
if(::system(_line.data()) == -1) {
_es << strerror(errno) << '\n';
}
}
// ------------------------------------------------------------------------------------------------
// Procedure: clear
void Shell::_clear() {
if(::system(_line.data()) == -1) {
_es << strerror(errno) << '\n';
}
}
// ------------------------------------------------------------------------------------------------
// Procedure: tail
void Shell::_tail() {
if(::system(_line.data()) == -1) {
_es << strerror(errno) << '\n';
}
}
// ------------------------------------------------------------------------------------------------
// Procedure: head
void Shell::_head() {
if(::system(_line.data()) == -1) {
_es << strerror(errno) << '\n';
}
}
// ------------------------------------------------------------------------------------------------
// Procedure: cat
void Shell::_cat() {
if(::system(_line.data()) == -1) {
_es << strerror(errno) << '\n';
}
}
// ------------------------------------------------------------------------------------------------
// Procedure: cd
void Shell::_cd() {
size_t ptr = 0;
for(; ptr + 1 < _line.size(); ptr++) {
if(_line[ptr]=='c' && _line[ptr+1]=='d') {
ptr = ptr + 2;
break;
}
}
while(ptr < _line.size() && _line[ptr] == ' ') {
ptr++;
}
if(::chdir(_line.data()+ptr) == -1) {
_es << strerror(errno) << ": " << _line.data()+ptr << '\n';
}
}
// ------------------------------------------------------------------------------------------------
// Procedure: rm
void Shell::_rm() {
if(::system(_line.data()) == -1) {
_es << strerror(errno) << '\n';
}
}
// ------------------------------------------------------------------------------------------------
// Procedure: pwd
void Shell::_pwd() {
if(::system(_line.data()) == -1) {
_es << strerror(errno) << '\n';
}
}
// ------------------------------------------------------------------------------------------------
// Procedure: ls
void Shell::_ls() {
if(::system(_line.data()) == -1) {
_es << strerror(errno) << '\n';
}
}
}; // end of namespace ot. -----------------------------------------------------------------------
|