mirror of https://gitee.com/bigwinds/arangodb
mini cleanup
This commit is contained in:
parent
7452c70a3b
commit
ccf7e4f131
|
@ -61,7 +61,7 @@ ConsoleThread::ConsoleThread (ApplicationServer* applicationServer,
|
||||||
: Thread("console"),
|
: Thread("console"),
|
||||||
_applicationServer(applicationServer),
|
_applicationServer(applicationServer),
|
||||||
_applicationV8(applicationV8),
|
_applicationV8(applicationV8),
|
||||||
_context(0),
|
_context(nullptr),
|
||||||
_vocbase(vocbase),
|
_vocbase(vocbase),
|
||||||
_done(0),
|
_done(0),
|
||||||
_userAborted(false) {
|
_userAborted(false) {
|
||||||
|
@ -151,13 +151,13 @@ void ConsoleThread::inner () {
|
||||||
char* input = console.prompt("arangod> ");
|
char* input = console.prompt("arangod> ");
|
||||||
|
|
||||||
if (_userAborted) {
|
if (_userAborted) {
|
||||||
if (input != 0) {
|
if (input != nullptr) {
|
||||||
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, input);
|
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, input);
|
||||||
}
|
}
|
||||||
throw "user aborted";
|
throw "user aborted";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input == 0) {
|
if (input == nullptr) {
|
||||||
_userAborted = true;
|
_userAborted = true;
|
||||||
|
|
||||||
// this will be caught by "run"
|
// this will be caught by "run"
|
||||||
|
|
|
@ -111,25 +111,29 @@ Thread::Thread (std::string const& name)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Thread::~Thread () {
|
Thread::~Thread () {
|
||||||
int res;
|
|
||||||
|
|
||||||
if (_running != 0) {
|
if (_running != 0) {
|
||||||
if (! isSilent()) {
|
if (! isSilent()) {
|
||||||
LOG_WARNING("forcefully shutting down thread '%s'", _name.c_str());
|
LOG_WARNING("forcefully shutting down thread '%s'", _name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
res = TRI_StopThread(&_thread);
|
int res = TRI_StopThread(&_thread);
|
||||||
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
LOG_WARNING("unable to stop thread '%s': %s", _name.c_str(), TRI_errno_string(res));
|
errno = res;
|
||||||
|
TRI_set_errno(TRI_ERROR_SYS_ERROR);
|
||||||
|
|
||||||
|
LOG_WARNING("unable to stop thread '%s': %s", _name.c_str(), TRI_last_error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! _joined) {
|
if (! _joined) {
|
||||||
res = TRI_DetachThread(&_thread);
|
int res = TRI_DetachThread(&_thread);
|
||||||
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
LOG_WARNING("unable to detach thread '%s': %s", _name.c_str(), TRI_errno_string(res));
|
errno = res;
|
||||||
|
TRI_set_errno(TRI_ERROR_SYS_ERROR);
|
||||||
|
|
||||||
|
LOG_WARNING("unable to detach thread '%s': %s", _name.c_str(), TRI_last_error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,9 +240,12 @@ int Thread::shutdown () {
|
||||||
int res = TRI_StopThread(&_thread);
|
int res = TRI_StopThread(&_thread);
|
||||||
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
|
errno = res;
|
||||||
|
TRI_set_errno(TRI_ERROR_SYS_ERROR);
|
||||||
|
|
||||||
LOG_WARNING("unable to stop thread '%s': %s",
|
LOG_WARNING("unable to stop thread '%s': %s",
|
||||||
_name.c_str(),
|
_name.c_str(),
|
||||||
TRI_errno_string(res));
|
TRI_last_error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,9 +140,8 @@ void LineEditor::sortAlternatives (vector<string>& completions) {
|
||||||
|
|
||||||
|
|
||||||
void LineEditor::prepareShell () {
|
void LineEditor::prepareShell () {
|
||||||
if (!_shellImpl) {
|
if (! _shellImpl) {
|
||||||
initializeShell();
|
initializeShell();
|
||||||
// assert _shellImpl != 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
|
@ -46,8 +46,7 @@ using namespace std;
|
||||||
using namespace triagens;
|
using namespace triagens;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
Completer* COMPLETER;
|
||||||
Completer * COMPLETER;
|
|
||||||
|
|
||||||
static char WordBreakCharacters[] = {
|
static char WordBreakCharacters[] = {
|
||||||
' ', '\t', '\n', '"', '\\', '\'', '`', '@',
|
' ', '\t', '\n', '"', '\\', '\'', '`', '@',
|
||||||
|
@ -59,7 +58,7 @@ namespace {
|
||||||
static size_t currentIndex;
|
static size_t currentIndex;
|
||||||
static vector<string> result;
|
static vector<string> result;
|
||||||
// compute the possible completion
|
// compute the possible completion
|
||||||
if(state == 0) {
|
if (state == 0) {
|
||||||
COMPLETER->getAlternatives(text, result);
|
COMPLETER->getAlternatives(text, result);
|
||||||
LineEditor::sortAlternatives(result);
|
LineEditor::sortAlternatives(result);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +73,6 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char** AttemptedCompletion (char const* text, int start, int end) {
|
static char** AttemptedCompletion (char const* text, int start, int end) {
|
||||||
char** result;
|
char** result;
|
||||||
|
|
||||||
|
@ -110,15 +108,16 @@ namespace {
|
||||||
/// @brief constructs a new editor
|
/// @brief constructs a new editor
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ReadlineShell::ReadlineShell(std::string const& history, Completer *completer)
|
ReadlineShell::ReadlineShell (std::string const& history,
|
||||||
|
Completer* completer)
|
||||||
: ShellImplementation(history, completer) {
|
: ShellImplementation(history, completer) {
|
||||||
|
|
||||||
COMPLETER = completer;
|
COMPLETER = completer;
|
||||||
|
|
||||||
rl_initialize();
|
rl_initialize();
|
||||||
|
|
||||||
rl_attempted_completion_function = AttemptedCompletion;
|
rl_attempted_completion_function = AttemptedCompletion;
|
||||||
rl_completer_word_break_characters = WordBreakCharacters;
|
rl_completer_word_break_characters = WordBreakCharacters;
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
rl_catch_signals = 0;
|
rl_catch_signals = 0;
|
||||||
|
@ -134,9 +133,8 @@ ReadlineShell::ReadlineShell(std::string const& history, Completer *completer)
|
||||||
/// @brief line editor open
|
/// @brief line editor open
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool ReadlineShell::open(bool autoComplete) {
|
bool ReadlineShell::open (bool autoComplete) {
|
||||||
if (autoComplete) {
|
if (autoComplete) {
|
||||||
|
|
||||||
// issue #289: do not append a space after completion
|
// issue #289: do not append a space after completion
|
||||||
rl_completion_append_character = '\0';
|
rl_completion_append_character = '\0';
|
||||||
|
|
||||||
|
@ -168,7 +166,6 @@ bool ReadlineShell::open(bool autoComplete) {
|
||||||
stifle_history(1000);
|
stifle_history(1000);
|
||||||
|
|
||||||
_state = STATE_OPENED;
|
_state = STATE_OPENED;
|
||||||
|
|
||||||
return read_history(historyPath().c_str()) == 0;
|
return read_history(historyPath().c_str()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +173,7 @@ bool ReadlineShell::open(bool autoComplete) {
|
||||||
/// @brief line editor shutdown
|
/// @brief line editor shutdown
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool ReadlineShell::close() {
|
bool ReadlineShell::close () {
|
||||||
if (_state != STATE_OPENED) {
|
if (_state != STATE_OPENED) {
|
||||||
// avoid duplicate saving of history
|
// avoid duplicate saving of history
|
||||||
return true;
|
return true;
|
||||||
|
@ -206,7 +203,7 @@ bool ReadlineShell::close() {
|
||||||
/// @brief get the history file path
|
/// @brief get the history file path
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
string ReadlineShell::historyPath() {
|
string ReadlineShell::historyPath () {
|
||||||
string path;
|
string path;
|
||||||
|
|
||||||
if (getenv("HOME")) {
|
if (getenv("HOME")) {
|
||||||
|
@ -223,7 +220,7 @@ string ReadlineShell::historyPath() {
|
||||||
/// @brief add to history
|
/// @brief add to history
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void ReadlineShell::addHistory(char const* str) {
|
void ReadlineShell::addHistory (char const* str) {
|
||||||
if (*str == '\0') {
|
if (*str == '\0') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -254,13 +251,14 @@ void ReadlineShell::addHistory(char const* str) {
|
||||||
/// @brief save history
|
/// @brief save history
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool ReadlineShell::writeHistory() {
|
bool ReadlineShell::writeHistory () {
|
||||||
return (write_history(historyPath().c_str()) == 0);
|
return (write_history(historyPath().c_str()) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char * ReadlineShell::getLine(char const * input) {
|
char * ReadlineShell::getLine (char const * input) {
|
||||||
return readline(input);
|
return readline(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- END-OF-FILE
|
// --SECTION-- END-OF-FILE
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue