1
0
Fork 0

mini cleanup

This commit is contained in:
Jan Steemann 2014-10-27 22:47:36 +01:00
parent 7452c70a3b
commit ccf7e4f131
4 changed files with 33 additions and 29 deletions

View File

@ -61,7 +61,7 @@ ConsoleThread::ConsoleThread (ApplicationServer* applicationServer,
: Thread("console"),
_applicationServer(applicationServer),
_applicationV8(applicationV8),
_context(0),
_context(nullptr),
_vocbase(vocbase),
_done(0),
_userAborted(false) {
@ -151,13 +151,13 @@ void ConsoleThread::inner () {
char* input = console.prompt("arangod> ");
if (_userAborted) {
if (input != 0) {
if (input != nullptr) {
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, input);
}
throw "user aborted";
}
if (input == 0) {
if (input == nullptr) {
_userAborted = true;
// this will be caught by "run"

View File

@ -111,25 +111,29 @@ Thread::Thread (std::string const& name)
////////////////////////////////////////////////////////////////////////////////
Thread::~Thread () {
int res;
if (_running != 0) {
if (! isSilent()) {
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) {
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) {
res = TRI_DetachThread(&_thread);
int res = TRI_DetachThread(&_thread);
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);
if (res != TRI_ERROR_NO_ERROR) {
errno = res;
TRI_set_errno(TRI_ERROR_SYS_ERROR);
LOG_WARNING("unable to stop thread '%s': %s",
_name.c_str(),
TRI_errno_string(res));
TRI_last_error());
}
}

View File

@ -140,9 +140,8 @@ void LineEditor::sortAlternatives (vector<string>& completions) {
void LineEditor::prepareShell () {
if (!_shellImpl) {
if (! _shellImpl) {
initializeShell();
// assert _shellImpl != 0;
}
}
// -----------------------------------------------------------------------------

View File

@ -46,8 +46,7 @@ using namespace std;
using namespace triagens;
namespace {
Completer * COMPLETER;
Completer* COMPLETER;
static char WordBreakCharacters[] = {
' ', '\t', '\n', '"', '\\', '\'', '`', '@',
@ -59,7 +58,7 @@ namespace {
static size_t currentIndex;
static vector<string> result;
// compute the possible completion
if(state == 0) {
if (state == 0) {
COMPLETER->getAlternatives(text, result);
LineEditor::sortAlternatives(result);
}
@ -74,7 +73,6 @@ namespace {
}
}
static char** AttemptedCompletion (char const* text, int start, int end) {
char** result;
@ -110,15 +108,16 @@ namespace {
/// @brief constructs a new editor
////////////////////////////////////////////////////////////////////////////////
ReadlineShell::ReadlineShell(std::string const& history, Completer *completer)
ReadlineShell::ReadlineShell (std::string const& history,
Completer* completer)
: ShellImplementation(history, completer) {
COMPLETER = completer;
COMPLETER = completer;
rl_initialize();
rl_initialize();
rl_attempted_completion_function = AttemptedCompletion;
rl_completer_word_break_characters = WordBreakCharacters;
rl_attempted_completion_function = AttemptedCompletion;
rl_completer_word_break_characters = WordBreakCharacters;
#ifndef __APPLE__
rl_catch_signals = 0;
@ -134,9 +133,8 @@ ReadlineShell::ReadlineShell(std::string const& history, Completer *completer)
/// @brief line editor open
////////////////////////////////////////////////////////////////////////////////
bool ReadlineShell::open(bool autoComplete) {
bool ReadlineShell::open (bool autoComplete) {
if (autoComplete) {
// issue #289: do not append a space after completion
rl_completion_append_character = '\0';
@ -168,7 +166,6 @@ bool ReadlineShell::open(bool autoComplete) {
stifle_history(1000);
_state = STATE_OPENED;
return read_history(historyPath().c_str()) == 0;
}
@ -176,7 +173,7 @@ bool ReadlineShell::open(bool autoComplete) {
/// @brief line editor shutdown
////////////////////////////////////////////////////////////////////////////////
bool ReadlineShell::close() {
bool ReadlineShell::close () {
if (_state != STATE_OPENED) {
// avoid duplicate saving of history
return true;
@ -206,7 +203,7 @@ bool ReadlineShell::close() {
/// @brief get the history file path
////////////////////////////////////////////////////////////////////////////////
string ReadlineShell::historyPath() {
string ReadlineShell::historyPath () {
string path;
if (getenv("HOME")) {
@ -223,7 +220,7 @@ string ReadlineShell::historyPath() {
/// @brief add to history
////////////////////////////////////////////////////////////////////////////////
void ReadlineShell::addHistory(char const* str) {
void ReadlineShell::addHistory (char const* str) {
if (*str == '\0') {
return;
}
@ -254,13 +251,14 @@ void ReadlineShell::addHistory(char const* str) {
/// @brief save history
////////////////////////////////////////////////////////////////////////////////
bool ReadlineShell::writeHistory() {
bool ReadlineShell::writeHistory () {
return (write_history(historyPath().c_str()) == 0);
}
char * ReadlineShell::getLine(char const * input) {
char * ReadlineShell::getLine (char const * input) {
return readline(input);
}
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------