1
0
Fork 0

Merge branch 'devel' of github.com:triAGENS/ArangoDB into devel

This commit is contained in:
Michael Hackstein 2014-07-30 09:42:02 +02:00
commit 3c1489c180
7 changed files with 177 additions and 157 deletions

View File

@ -33,7 +33,7 @@
#include "BasicsC/files.h"
using namespace std;
using namespace triagentriagens;
using namespace triagens;
// -----------------------------------------------------------------------------
// --SECTION-- class DummyShell
@ -47,10 +47,9 @@ using namespace triagentriagens;
/// @brief constructs a new editor
////////////////////////////////////////////////////////////////////////////////
DummyShell::DummyShell (std::string const& history)
: _current(),
_historyFilename(history),
_state(STATE_NONE) {
DummyShell::DummyShell (std::string const& history,
Completer* completer)
: ShellImplementation(history, completer) {
}
////////////////////////////////////////////////////////////////////////////////
@ -83,29 +82,6 @@ bool DummyShell::close () {
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get the history file path
////////////////////////////////////////////////////////////////////////////////
string DummyShell::historyPath () {
return "";
}
////////////////////////////////////////////////////////////////////////////////
/// @brief add to history
////////////////////////////////////////////////////////////////////////////////
void DummyShell::addHistory (char const* str) {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief save history
////////////////////////////////////////////////////////////////////////////////
bool DummyShell::writeHistory () {
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief line editor prompt
////////////////////////////////////////////////////////////////////////////////
@ -137,7 +113,7 @@ char* DummyShell::prompt (char const* prompt) {
p = dotdot.c_str();
if (cin.eof()) {
return 0;
return nullptr;
}
_current += sep;
@ -164,7 +140,7 @@ char* DummyShell::prompt (char const* prompt) {
// extend line and check
_current += result;
bool ok = isComplete(_current, lineno, strlen(result));
bool ok = _completer->isComplete(_current, lineno, strlen(result));
// stop if line is complete
if (ok) {
@ -173,11 +149,46 @@ char* DummyShell::prompt (char const* prompt) {
}
char* line = TRI_DuplicateStringZ(TRI_UNKNOWN_MEM_ZONE, _current.c_str());
_current.clear();
return line;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get the history file path
////////////////////////////////////////////////////////////////////////////////
string DummyShell::historyPath () {
return "";
}
////////////////////////////////////////////////////////////////////////////////
/// @brief add to history
////////////////////////////////////////////////////////////////////////////////
void DummyShell::addHistory (char const* str) {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief save history
////////////////////////////////////////////////////////////////////////////////
bool DummyShell::writeHistory () {
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the characters which the user has typed
/// @arg is the prompt of the shell
/// Note: this is the interface between our shell world and some implementation
/// of key events (linenoise, readline)
////////////////////////////////////////////////////////////////////////////////
char* DummyShell::getLine (char const* prompt) {
return this->prompt(prompt);
}
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------

View File

@ -39,21 +39,17 @@
#include "V8/v8-utils.h"
namespace triagens {
using namespace std;
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Shell
/// @{
////////////////////////////////////////////////////////////////////////////////
class DummyShell : public ShellImplementation {
public:
////////////////////////////////////////////////////////////////////////////////
/// public constructor, destructor
////////////////////////////////////////////////////////////////////////////////
DummyShell(string const& history, Completer *);
DummyShell (std::string const& history,
Completer*);
virtual ~DummyShell();
@ -69,6 +65,12 @@ namespace triagens {
virtual bool close();
////////////////////////////////////////////////////////////////////////////////
/// @brief line editor prompt
////////////////////////////////////////////////////////////////////////////////
virtual char* prompt (char const* prompt);
////////////////////////////////////////////////////////////////////////////////
/// @brief get the history file path
///
@ -99,10 +101,6 @@ namespace triagens {
virtual char* getLine (char const*);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
};
}
#endif

View File

@ -28,14 +28,14 @@
/// @author Copyright 2011-2014, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32
#include "LinenoiseShell.h"
#elif TRI_HAVE_LINENOISE
#elif defined TRI_HAVE_LINENOISE
#include "LinenoiseShell.h"
#else
#elif defined TRI_HAVE_READLINE
#include "ReadlineShell.h"
#else
#include "DummyShell.h"
#endif
#include "ShellImplFactory.h"
@ -43,15 +43,19 @@
using namespace triagens;
using namespace std;
ShellImplementation * ShellImplFactory::buildShell (string const & history, Completer * completer) {
ShellImplementation* ShellImplFactory::buildShell (string const & history,
Completer* completer) {
#ifdef _WIN32
//under windows the readline is not compilable
return new LinenoiseShell(history, completer);
#elif defined TRI_HAVE_LINENOISE
return new LinenoiseShell(history, completer);
#else
#elif defined TRI_HAVE_READLINE
return new ReadlineShell(history, completer);
#else
// last resort!
return new DummyShell(history, completer);
#endif
}

View File

@ -32,7 +32,9 @@
#include "BasicsC/tri-strings.h"
using namespace std;
namespace triagens {
// -----------------------------------------------------------------------------
// --SECTION-- class ShellImplementation
// -----------------------------------------------------------------------------
@ -45,7 +47,8 @@ namespace triagens {
/// @brief constructs a new editor
////////////////////////////////////////////////////////////////////////////////
ShellImplementation::ShellImplementation (string const& history, Completer * completer)
ShellImplementation::ShellImplementation (string const& history,
Completer* completer)
: _current(),
_historyFilename(history),
_state(STATE_NONE),
@ -91,11 +94,11 @@ namespace triagens {
p = dotdot.c_str();
if (result == 0) {
if (result == nullptr) {
// give up, if the user pressed control-D on the top-most level
if (_current.empty()) {
return 0;
return nullptr;
}
// otherwise clear current content
@ -143,7 +146,9 @@ namespace triagens {
return line;
}
}
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------

View File

@ -37,10 +37,13 @@
namespace triagens {
class ShellImplementation {
////////////////////////////////////////////////////////////////////////////////
/// @brief state of the console protected types
////////////////////////////////////////////////////////////////////////////////
protected:
typedef enum {
STATE_NONE = 0,
STATE_OPENED,
@ -49,6 +52,7 @@ namespace triagens {
console_state_e;
public:
////////////////////////////////////////////////////////////////////////////////
/// public constructor, destructor
////////////////////////////////////////////////////////////////////////////////
@ -102,10 +106,6 @@ namespace triagens {
virtual char* getLine (const char*) = 0;
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- protected variables
// -----------------------------------------------------------------------------
@ -138,7 +138,9 @@ namespace triagens {
};
}
#endif
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------