-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.cpp
More file actions
83 lines (76 loc) · 2.49 KB
/
shell.cpp
File metadata and controls
83 lines (76 loc) · 2.49 KB
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
/*
* This file is part of Torus.
* Torus is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Torus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with Torus. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctime>
#include <iostream>
#include <string>
#include <core/config.h>
#include <library/string.h>
#include <core/torus.h>
#include <shell.h>
#include <debug_support/callstack.h>
std::string _get_curr_datetime() {
std::string r;
t_byte buffer[255];
std::time_t t = std::time(NULL);
std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", std::localtime(&t));
r = buffer;
return r;
}
TorusShell::TorusShell() {
}
void * TorusShell::run() {
bool continue_proc = true;
std::setlocale(LC_ALL, "en_US.UTF-8");
t_byte c;
t_byte buffer[256];
t_byte * stripped_buffer;
udword_t counter = 0;
_log_file.open(toruscfg.log_filename, std::ios_base::out | std::ios_base::app);
//DBG_MSG_INF("Starting User Interface Thread.");
do {
c = (t_byte)getchar();
if (c != 10) {
buffer[counter] = c;
if (counter < 255) {
counter++;
}
} else {
buffer[counter] = 0;
stripped_buffer = buffer;
if (counter > 0) {
STRIP(stripped_buffer);
}
if (strlen(stripped_buffer) == 1 && stripped_buffer[0] == 'x') {
continue_proc = false;
torus.shutdown();
}
// if (torusshell.execute_order(stripped_buffer)) {
// continue_proc = false;
// } else {
// counter = 0;
// }
counter = 0;
}
} while (continue_proc);
_log_file.close();
return NULL;
}
void TorusShell::print(const std::string& str) {
print(to_wstring(str).c_str());
}
void TorusShell::print(const wchar_t* s) {
std::wstring t = to_wstring(_get_curr_datetime());
std::wcout << "[" << t << "] " << s << std::endl;
_log_file << L"[" << t << L"] " << s << std::endl;
}