in src/IO.cpp [64:113]
int myReadConsole(const char* prompt, unsigned char* buf, int len, int addToHistory) {
static bool inited = false;
if (!inited) {
if (addToHistory) {
inited = true;
try {
initRWrapper();
} catch (std::exception const &e) {
std::cerr << "Error during RWrapper startup: " << e.what() << "\n";
signal(SIGABRT, SIG_DFL);
abort();
}
rpiService->mainLoop();
} else {
buf[0] = 0;
return 0;
}
}
CPP_BEGIN
if (rpiService == nullptr) {
// Read console happened during termination
signal(SIGABRT, SIG_DFL);
abort();
}
std::string s;
if (addToHistory && !strncmp(prompt, "Browse[", strlen("Browse["))) {
// That's browser prompt, we ignore them
s = "f\n";
} else {
s = translateToNative(rpiService->readLineHandler(prompt));
}
if (rpiService->terminate) {
R_interrupts_pending = 1;
buf[0] = 0;
return 0;
}
if (s.empty() || s.back() != '\n') {
s += '\n';
}
if (s.size() >= len) {
s.erase(s.begin() + (len - 1), s.end());
s.back() = '\n';
}
strcpy((char*)buf, s.c_str());
return s.size();
CPP_END_VOID_NOINTR
return 0;
}