mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel
This commit is contained in:
commit
17cd12d32c
|
@ -0,0 +1,2 @@
|
|||
linenoise_example
|
||||
*.exe
|
|
@ -0,0 +1,47 @@
|
|||
# Linenoise
|
||||
|
||||
A minimal, zero-config, BSD licensed, readline replacement.
|
||||
|
||||
News: linenoise now includes minimal completion support, thanks to Pieter Noordhuis (@pnoordhuis).
|
||||
|
||||
News: linenoise is now part of [Android](http://android.git.kernel.org/?p=platform/system/core.git;a=tree;f=liblinenoise;h=56450eaed7f783760e5e6a5993ef75cde2e29dea;hb=HEAD Android)!
|
||||
|
||||
## Can a line editing library be 20k lines of code?
|
||||
|
||||
Line editing with some support for history is a really important feature for command line utilities. Instead of retyping almost the same stuff again and again it's just much better to hit the up arrow and edit on syntax errors, or in order to try a slightly different command. But apparently code dealing with terminals is some sort of Black Magic: readline is 30k lines of code, libedit 20k. Is it reasonable to link small utilities to huge libraries just to get a minimal support for line editing?
|
||||
|
||||
So what usually happens is either:
|
||||
|
||||
* Large programs with configure scripts disabling line editing if readline is not present in the system, or not supporting it at all since readline is GPL licensed and libedit (the BSD clone) is not as known and available as readline is (Real world example of this problem: Tclsh).
|
||||
* Smaller programs not using a configure script not supporting line editing at all (A problem we had with Redis-cli for instance).
|
||||
|
||||
The result is a pollution of binaries without line editing support.
|
||||
|
||||
So I spent more or less two hours doing a reality check resulting in this little library: is it *really* needed for a line editing library to be 20k lines of code? Apparently not, it is possibe to get a very small, zero configuration, trivial to embed library, that solves the problem. Smaller programs will just include this, supporing line editing out of the box. Larger programs may use this little library or just checking with configure if readline/libedit is available and resorting to linenoise if not.
|
||||
|
||||
## Terminals, in 2010.
|
||||
|
||||
Apparently almost every terminal you can happen to use today has some kind of support for VT100 alike escape sequences. So I tried to write a lib using just very basic VT100 features. The resulting library appears to work everywhere I tried to use it.
|
||||
|
||||
Since it's so young I guess there are a few bugs, or the lib may not compile or work with some operating system, but it's a matter of a few weeks and eventually we'll get it right, and there will be no excuses for not shipping command line tools without built-in line editing support.
|
||||
|
||||
The library is currently less than 2000 lines of code. In order to use it in your project just look at the *example.c* file in the source distribution, it is trivial. Linenoise is BSD code, so you can use both in free software and commercial software.
|
||||
|
||||
## Tested with...
|
||||
|
||||
* Linux text only console ($TERM = linux)
|
||||
* Linux KDE terminal application ($TERM = xterm)
|
||||
* Linux xterm ($TERM = xterm)
|
||||
* Mac OS X iTerm ($TERM = xterm)
|
||||
* Mac OS X default Terminal.app ($TERM = xterm)
|
||||
* OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen)
|
||||
* IBM AIX 6.1
|
||||
* FreeBSD xterm ($TERM = xterm)
|
||||
|
||||
Please test it everywhere you can and report back!
|
||||
|
||||
## Let's push this forward!
|
||||
|
||||
Please fork it and add something interesting and send me a pull request. What's especially interesting are fixes, new key bindings, completion.
|
||||
|
||||
Send feedbacks to antirez at gmail
|
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "linenoise.h"
|
||||
|
||||
#ifndef NO_COMPLETION
|
||||
void completion(const char *buf, linenoiseCompletions *lc) {
|
||||
if (buf[0] == 'h') {
|
||||
linenoiseAddCompletion(lc,"hello");
|
||||
linenoiseAddCompletion(lc,"hello there");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *line;
|
||||
#ifdef HAVE_MULTILINE
|
||||
/* Note: multiline support has not yet been integrated */
|
||||
char *prgname = argv[0];
|
||||
|
||||
/* Parse options, with --multiline we enable multi line editing. */
|
||||
while(argc > 1) {
|
||||
argc--;
|
||||
argv++;
|
||||
if (!strcmp(*argv,"--multiline")) {
|
||||
linenoiseSetMultiLine(1);
|
||||
printf("Multi-line mode enabled.\n");
|
||||
} else {
|
||||
fprintf(stderr, "Usage: %s [--multiline]\n", prgname);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NO_COMPLETION
|
||||
/* Set the completion callback. This will be called every time the
|
||||
* user uses the <tab> key. */
|
||||
linenoiseSetCompletionCallback(completion);
|
||||
#endif
|
||||
|
||||
/* Load history from file. The history file is just a plain text file
|
||||
* where entries are separated by newlines. */
|
||||
linenoiseHistoryLoad("history.txt"); /* Load the history at startup */
|
||||
|
||||
/* Now this is the main loop of the typical linenoise-based application.
|
||||
* The call to linenoise() will block as long as the user types something
|
||||
* and presses enter.
|
||||
*
|
||||
* The typed string is returned as a malloc() allocated string by
|
||||
* linenoise, so the user needs to free() it. */
|
||||
while((line = linenoise("hello> ")) != NULL) {
|
||||
/* Do something with the string. */
|
||||
if (line[0] != '\0' && line[0] != '/') {
|
||||
printf("echo: '%s'\n", line);
|
||||
linenoiseHistoryAdd(line); /* Add to the history. */
|
||||
linenoiseHistorySave("history.txt"); /* Save the history on disk. */
|
||||
} else if (!strncmp(line,"/historylen",11)) {
|
||||
/* The "/historylen" command will change the history len. */
|
||||
int len = atoi(line+11);
|
||||
linenoiseHistorySetMaxLen(len);
|
||||
} else if (line[0] == '/') {
|
||||
printf("Unreconized command: %s\n", line);
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,61 @@
|
|||
/* linenoise.h -- guerrilla line editing library against the idea that a
|
||||
* line editing lib needs to be 20,000 lines of C code.
|
||||
*
|
||||
* See linenoise.c for more information.
|
||||
*
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
|
||||
* Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __LINENOISE_H
|
||||
#define __LINENOISE_H
|
||||
|
||||
#ifndef NO_COMPLETION
|
||||
typedef struct linenoiseCompletions {
|
||||
size_t len;
|
||||
char **cvec;
|
||||
} linenoiseCompletions;
|
||||
|
||||
typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *);
|
||||
void linenoiseSetCompletionCallback(linenoiseCompletionCallback *);
|
||||
void linenoiseAddCompletion(linenoiseCompletions *, const char *);
|
||||
#endif
|
||||
|
||||
char *linenoise(const char *prompt);
|
||||
int linenoiseHistoryAdd(const char *line);
|
||||
int linenoiseHistorySetMaxLen(int len);
|
||||
int linenoiseHistoryGetMaxLen(void);
|
||||
int linenoiseHistorySave(const char *filename);
|
||||
int linenoiseHistoryLoad(const char *filename);
|
||||
void linenoiseHistoryFree(void);
|
||||
char **linenoiseHistory(int *len);
|
||||
int linenoiseColumns(void);
|
||||
|
||||
#endif /* __LINENOISE_H */
|
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* UTF-8 utility functions
|
||||
*
|
||||
* (c) 2010 Steve Bennett <steveb@workware.net.au>
|
||||
*
|
||||
* See LICENCE for licence details.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "utf8.h"
|
||||
|
||||
#ifdef USE_UTF8
|
||||
int utf8_fromunicode(char *p, unsigned short uc)
|
||||
{
|
||||
if (uc <= 0x7f) {
|
||||
*p = uc;
|
||||
return 1;
|
||||
}
|
||||
else if (uc <= 0x7ff) {
|
||||
*p++ = 0xc0 | ((uc & 0x7c0) >> 6);
|
||||
*p = 0x80 | (uc & 0x3f);
|
||||
return 2;
|
||||
}
|
||||
else {
|
||||
*p++ = 0xe0 | ((uc & 0xf000) >> 12);
|
||||
*p++ = 0x80 | ((uc & 0xfc0) >> 6);
|
||||
*p = 0x80 | (uc & 0x3f);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
int utf8_charlen(int c)
|
||||
{
|
||||
if ((c & 0x80) == 0) {
|
||||
return 1;
|
||||
}
|
||||
if ((c & 0xe0) == 0xc0) {
|
||||
return 2;
|
||||
}
|
||||
if ((c & 0xf0) == 0xe0) {
|
||||
return 3;
|
||||
}
|
||||
if ((c & 0xf8) == 0xf0) {
|
||||
return 4;
|
||||
}
|
||||
/* Invalid sequence */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int utf8_strlen(const char *str, int bytelen)
|
||||
{
|
||||
int charlen = 0;
|
||||
if (bytelen < 0) {
|
||||
bytelen = strlen(str);
|
||||
}
|
||||
while (bytelen) {
|
||||
int c;
|
||||
int l = utf8_tounicode(str, &c);
|
||||
charlen++;
|
||||
str += l;
|
||||
bytelen -= l;
|
||||
}
|
||||
return charlen;
|
||||
}
|
||||
|
||||
int utf8_index(const char *str, int index)
|
||||
{
|
||||
const char *s = str;
|
||||
while (index--) {
|
||||
int c;
|
||||
s += utf8_tounicode(s, &c);
|
||||
}
|
||||
return s - str;
|
||||
}
|
||||
|
||||
int utf8_charequal(const char *s1, const char *s2)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
utf8_tounicode(s1, &c1);
|
||||
utf8_tounicode(s2, &c2);
|
||||
|
||||
return c1 == c2;
|
||||
}
|
||||
|
||||
int utf8_tounicode(const char *str, int *uc)
|
||||
{
|
||||
unsigned const char *s = (unsigned const char *)str;
|
||||
|
||||
if (s[0] < 0xc0) {
|
||||
*uc = s[0];
|
||||
return 1;
|
||||
}
|
||||
if (s[0] < 0xe0) {
|
||||
if ((s[1] & 0xc0) == 0x80) {
|
||||
*uc = ((s[0] & ~0xc0) << 6) | (s[1] & ~0x80);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (s[0] < 0xf0) {
|
||||
if (((str[1] & 0xc0) == 0x80) && ((str[2] & 0xc0) == 0x80)) {
|
||||
*uc = ((s[0] & ~0xe0) << 12) | ((s[1] & ~0x80) << 6) | (s[2] & ~0x80);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
/* Invalid sequence, so just return the byte */
|
||||
*uc = *s;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,79 @@
|
|||
#ifndef UTF8_UTIL_H
|
||||
#define UTF8_UTIL_H
|
||||
/**
|
||||
* UTF-8 utility functions
|
||||
*
|
||||
* (c) 2010 Steve Bennett <steveb@workware.net.au>
|
||||
*
|
||||
* See LICENCE for licence details.
|
||||
*/
|
||||
|
||||
#ifndef USE_UTF8
|
||||
#include <ctype.h>
|
||||
|
||||
/* No utf-8 support. 1 byte = 1 char */
|
||||
#define utf8_strlen(S, B) ((B) < 0 ? (int)strlen(S) : (B))
|
||||
#define utf8_tounicode(S, CP) (*(CP) = (unsigned char)*(S), 1)
|
||||
#define utf8_index(C, I) (I)
|
||||
#define utf8_charlen(C) 1
|
||||
|
||||
#else
|
||||
/**
|
||||
* Converts the given unicode codepoint (0 - 0xffff) to utf-8
|
||||
* and stores the result at 'p'.
|
||||
*
|
||||
* Returns the number of utf-8 characters (1-3).
|
||||
*/
|
||||
int utf8_fromunicode(char *p, unsigned short uc);
|
||||
|
||||
/**
|
||||
* Returns the length of the utf-8 sequence starting with 'c'.
|
||||
*
|
||||
* Returns 1-4, or -1 if this is not a valid start byte.
|
||||
*
|
||||
* Note that charlen=4 is not supported by the rest of the API.
|
||||
*/
|
||||
int utf8_charlen(int c);
|
||||
|
||||
/**
|
||||
* Returns the number of characters in the utf-8
|
||||
* string of the given byte length.
|
||||
*
|
||||
* Any bytes which are not part of an valid utf-8
|
||||
* sequence are treated as individual characters.
|
||||
*
|
||||
* The string *must* be null terminated.
|
||||
*
|
||||
* Does not support unicode code points > \uffff
|
||||
*/
|
||||
int utf8_strlen(const char *str, int bytelen);
|
||||
|
||||
/**
|
||||
* Returns the byte index of the given character in the utf-8 string.
|
||||
*
|
||||
* The string *must* be null terminated.
|
||||
*
|
||||
* This will return the byte length of a utf-8 string
|
||||
* if given the char length.
|
||||
*/
|
||||
int utf8_index(const char *str, int charindex);
|
||||
|
||||
/**
|
||||
* Returns the unicode codepoint corresponding to the
|
||||
* utf-8 sequence 'str'.
|
||||
*
|
||||
* Stores the result in *uc and returns the number of bytes
|
||||
* consumed.
|
||||
*
|
||||
* If 'str' is null terminated, then an invalid utf-8 sequence
|
||||
* at the end of the string will be returned as individual bytes.
|
||||
*
|
||||
* If it is not null terminated, the length *must* be checked first.
|
||||
*
|
||||
* Does not support unicode code points > \uffff
|
||||
*/
|
||||
int utf8_tounicode(const char *str, int *uc);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -36,11 +36,6 @@
|
|||
// --SECTION-- Special Configuration Options
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup Configuration
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief enable calculation of timing figures
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -77,6 +72,18 @@
|
|||
|
||||
#undef TRI_ENABLE_MAINTAINER_MODE
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief enable readline
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#undef TRI_HAVE_READLINE
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief enable linenoise
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#undef TRI_HAVE_LINENOISE
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief configure command
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -101,12 +108,12 @@
|
|||
|
||||
#undef TRI_REPOSITORY_VERSION
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- END-OF-FILE
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||
|
|
|
@ -91,12 +91,32 @@ lib_libarango_a_SOURCES = \
|
|||
lib/ShapedJson/shape-accessor.c \
|
||||
lib/ShapedJson/shaped-json.c \
|
||||
lib/Statistics/statistics.cpp \
|
||||
lib/Utilities/LineEditor-readline.cpp \
|
||||
lib/Utilities/ScriptLoader.cpp \
|
||||
lib/Zip/ioapi.c \
|
||||
lib/Zip/unzip.c \
|
||||
lib/Zip/zip.c
|
||||
|
||||
if ENABLE_READLINE
|
||||
|
||||
lib_libarango_a_SOURCES += \
|
||||
lib/Utilities/LineEditor-readline.cpp
|
||||
|
||||
else
|
||||
if ENABLE_LINENOISE
|
||||
|
||||
lib_libarango_a_SOURCES += \
|
||||
lib/Utilities/LineEditor-linenoise.cpp \
|
||||
3rdParty/linenoise/linenoise.c \
|
||||
3rdParty/linenoise/utf8.c
|
||||
|
||||
else
|
||||
|
||||
lib_libarango_a_SOURCES += \
|
||||
lib/Utilities/LineEditor-dummy.cpp
|
||||
|
||||
endif
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
### @brief library "libarango.a", client part
|
||||
################################################################################
|
||||
|
|
|
@ -0,0 +1,185 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief line editor using getline
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2004-2013 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "LineEditor.h"
|
||||
|
||||
#include "BasicsC/tri-strings.h"
|
||||
#include "BasicsC/files.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- class LineEditor
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief constructs a new editor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LineEditor::LineEditor (std::string const& history)
|
||||
: _current(),
|
||||
_historyFilename(history),
|
||||
_state(STATE_NONE) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief destructor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LineEditor::~LineEditor () {
|
||||
close();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief line editor open
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool LineEditor::open (bool) {
|
||||
_state = STATE_OPENED;
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief line editor shutdown
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool LineEditor::close () {
|
||||
_state = STATE_CLOSED;
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the history file path
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
string LineEditor::historyPath () {
|
||||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief add to history
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LineEditor::addHistory (char const* str) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief save history
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool LineEditor::writeHistory () {
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief line editor prompt
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
char* LineEditor::prompt (char const* prompt) {
|
||||
string dotdot;
|
||||
char const* p = prompt;
|
||||
size_t len1 = strlen(prompt);
|
||||
size_t len2 = len1;
|
||||
size_t lineno = 0;
|
||||
|
||||
if (len1 < 3) {
|
||||
dotdot = "> ";
|
||||
len2 = 2;
|
||||
}
|
||||
else {
|
||||
dotdot = string(len1 - 2, '.') + "> ";
|
||||
}
|
||||
|
||||
char const* sep = "";
|
||||
|
||||
while (true) {
|
||||
fprintf(stdout, "%s", p);
|
||||
fflush(stdout);
|
||||
|
||||
string line;
|
||||
getline(cin, line);
|
||||
|
||||
p = dotdot.c_str();
|
||||
|
||||
if (cin.eof()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
_current += sep;
|
||||
sep = "\n";
|
||||
++lineno;
|
||||
|
||||
// remove any prompt at the beginning of the line
|
||||
char* result = TRI_DuplicateStringZ(TRI_UNKNOWN_MEM_ZONE, line.c_str());
|
||||
bool c1 = strncmp(result, prompt, len1) == 0;
|
||||
bool c2 = strncmp(result, dotdot.c_str(), len2) == 0;
|
||||
|
||||
while (c1 || c2) {
|
||||
if (c1) {
|
||||
result += len1;
|
||||
}
|
||||
else if (c2) {
|
||||
result += len2;
|
||||
}
|
||||
|
||||
c1 = strncmp(result, prompt, len1) == 0;
|
||||
c2 = strncmp(result, dotdot.c_str(), len2) == 0;
|
||||
}
|
||||
|
||||
// extend line and check
|
||||
_current += result;
|
||||
|
||||
bool ok = isComplete(_current, lineno, strlen(result));
|
||||
|
||||
// stop if line is complete
|
||||
if (ok) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char* line = TRI_DuplicateStringZ(TRI_UNKNOWN_MEM_ZONE, _current.c_str());
|
||||
_current.clear();
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- END-OF-FILE
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"
|
||||
// End:
|
|
@ -1,5 +1,5 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief abstract line editor
|
||||
/// @brief line editor using linenoise
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief abstract line editor
|
||||
/// @brief line editor using readline
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
|
|
|
@ -29,7 +29,9 @@
|
|||
|
||||
#ifdef TRI_HAVE_LINENOISE
|
||||
#include <linenoise.h>
|
||||
#else
|
||||
#endif
|
||||
|
||||
#ifdef TRI_HAVE_READLINE
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#endif
|
||||
|
@ -37,7 +39,7 @@
|
|||
#include "BasicsC/tri-strings.h"
|
||||
#include "V8/v8-utils.h"
|
||||
|
||||
#ifndef TRI_HAVE_LINENOISE
|
||||
#ifdef TRI_HAVE_READLINE
|
||||
#if RL_READLINE_VERSION >= 0x0500
|
||||
#define completion_matches rl_completion_matches
|
||||
#endif
|
||||
|
@ -57,12 +59,16 @@ using namespace std;
|
|||
/// @brief word break characters
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef TRI_HAVE_READLINE
|
||||
|
||||
static char WordBreakCharacters[] = {
|
||||
' ', '\t', '\n', '"', '\\', '\'', '`', '@',
|
||||
'<', '>', '=', ';', '|', '&', '{', '}', '(', ')',
|
||||
'\0'
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -71,6 +77,8 @@ static char WordBreakCharacters[] = {
|
|||
/// @brief completion generator
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef TRI_HAVE_READLINE
|
||||
|
||||
static char* CompletionGenerator (char const* text, int state) {
|
||||
static size_t currentIndex;
|
||||
static vector<string> result;
|
||||
|
@ -179,13 +187,13 @@ static char* CompletionGenerator (char const* text, int state) {
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief attempted completion
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef TRI_HAVE_LINENOISE
|
||||
|
||||
#else
|
||||
#ifdef TRI_HAVE_READLINE
|
||||
|
||||
static char** AttemptedCompletion (char const* text, int start, int end) {
|
||||
char** result;
|
||||
|
@ -233,13 +241,9 @@ V8LineEditor::V8LineEditor (v8::Handle<v8::Context> context, std::string const&
|
|||
|
||||
bool V8LineEditor::open (const bool autoComplete) {
|
||||
if (autoComplete) {
|
||||
#ifdef TRI_HAVE_LINENOISE
|
||||
|
||||
#else
|
||||
|
||||
#ifdef TRI_HAVE_READLINE
|
||||
rl_attempted_completion_function = AttemptedCompletion;
|
||||
rl_completer_word_break_characters = WordBreakCharacters;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -312,7 +312,7 @@ static v8::Handle<v8::Value> JS_ProcessJsonFile (v8::Arguments const& argv) {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public functions
|
||||
// --SECTION-- module initialisation
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -284,7 +284,7 @@ static void FillDistribution (v8::Handle<v8::Object> list,
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief decode a base64-encoded string
|
||||
/// @brief decodes a base64-encoded string
|
||||
///
|
||||
/// @FUN{internal.base64Decode(@FA{value})}
|
||||
///
|
||||
|
@ -312,7 +312,7 @@ static v8::Handle<v8::Value> JS_Base64Decode (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief base64-encode a string
|
||||
/// @brief encodes a string as base64
|
||||
///
|
||||
/// @FUN{internal.base64Encode(@FA{value})}
|
||||
///
|
||||
|
@ -340,7 +340,7 @@ static v8::Handle<v8::Value> JS_Base64Encode (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief parse a Javascript snippet, but do not execute it
|
||||
/// @brief parses a Javascript snippet, but do not execute it
|
||||
///
|
||||
/// @FUN{internal.parse(@FA{script})}
|
||||
///
|
||||
|
@ -839,7 +839,7 @@ static v8::Handle<v8::Value> JS_Exists (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the size of a file
|
||||
/// @brief gets the size of a file
|
||||
///
|
||||
/// @FUN{fs.size(@FA{path})}
|
||||
///
|
||||
|
@ -887,7 +887,7 @@ static v8::Handle<v8::Value> JS_Getline (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return the temporary directory
|
||||
/// @brief returns the temporary directory
|
||||
///
|
||||
/// @FUN{fs.getTempPath()}
|
||||
///
|
||||
|
@ -914,7 +914,7 @@ static v8::Handle<v8::Value> JS_GetTempPath (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return the name for a (new) temporary file
|
||||
/// @brief returns the name for a (new) temporary file
|
||||
///
|
||||
/// @FUN{fs.getTempFile(@FA{directory}, @FA{createFile})}
|
||||
///
|
||||
|
@ -1010,7 +1010,7 @@ static v8::Handle<v8::Value> JS_IsFile (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the directory tree
|
||||
/// @brief returns the directory listing
|
||||
///
|
||||
/// @FUN{fs.list(@FA{path})}
|
||||
///
|
||||
|
@ -1097,7 +1097,7 @@ static v8::Handle<v8::Value> JS_ListTree (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create a directory
|
||||
/// @brief creates a directory
|
||||
///
|
||||
/// @FUN{fs.makeDirectory(@FA{path})}
|
||||
///
|
||||
|
@ -1381,7 +1381,7 @@ static v8::Handle<v8::Value> JS_LogLevel (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief md5 sum
|
||||
/// @brief computes the md5 sum of a text
|
||||
///
|
||||
/// @FUN{internal.md5(@FA{text})}
|
||||
///
|
||||
|
@ -1422,7 +1422,7 @@ static v8::Handle<v8::Value> JS_Md5 (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generate random numbers
|
||||
/// @brief generates random numbers
|
||||
///
|
||||
/// @FUN{internal.genRandomNumbers(@FA{length})}
|
||||
///
|
||||
|
@ -1444,7 +1444,7 @@ static v8::Handle<v8::Value> JS_RandomNumbers (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generate random alpha-numbers
|
||||
/// @brief generates random alpha-numbers
|
||||
///
|
||||
/// @FUN{internal.genRandomAlphaNumbers(@FA{length})}
|
||||
///
|
||||
|
@ -1465,7 +1465,7 @@ static v8::Handle<v8::Value> JS_RandomAlphaNum (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief gernate a salt
|
||||
/// @brief generates a salt
|
||||
///
|
||||
/// @FUN{internal.genRandomSalt()}
|
||||
///
|
||||
|
@ -1484,7 +1484,7 @@ static v8::Handle<v8::Value> JS_RandomSalt (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief nonce generator
|
||||
/// @brief generates a nonce
|
||||
///
|
||||
/// @FUN{internal.createNonce()}
|
||||
///
|
||||
|
@ -1661,7 +1661,7 @@ static v8::Handle<v8::Value> JS_ProcessStatistics (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief generate a random number using OpenSSL
|
||||
/// @brief generates a random number using OpenSSL
|
||||
///
|
||||
/// @FUN{internal.rand()}
|
||||
///
|
||||
|
@ -2087,7 +2087,7 @@ static v8::Handle<v8::Value> JS_SPrintF (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sha256 sum
|
||||
/// @brief computes the sha256 sum
|
||||
///
|
||||
/// @FUN{internal.sha256(@FA{text})}
|
||||
///
|
||||
|
@ -2181,7 +2181,7 @@ static v8::Handle<v8::Value> JS_Wait (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief intentionally cause a segfault
|
||||
/// @brief intentionally causes a segfault
|
||||
///
|
||||
/// @FUN{internal.debugSegfault(@FA{message})}
|
||||
///
|
||||
|
@ -2206,7 +2206,7 @@ static v8::Handle<v8::Value> JS_DebugSegfault (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set a failure point
|
||||
/// @brief sets a failure point
|
||||
///
|
||||
/// @FUN{internal.debugSetFailAt(@FA{point})}
|
||||
///
|
||||
|
@ -2229,7 +2229,7 @@ static v8::Handle<v8::Value> JS_DebugSetFailAt (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief remove a failure point
|
||||
/// @brief removes a failure point
|
||||
///
|
||||
/// @FUN{internal.debugRemoveFailAt(@FA{point})}
|
||||
///
|
||||
|
@ -2252,7 +2252,7 @@ static v8::Handle<v8::Value> JS_DebugRemoveFailAt (v8::Arguments const& argv) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief clear all failure points
|
||||
/// @brief clears all failure points
|
||||
///
|
||||
/// @FUN{internal.debugClearFailAt()}
|
||||
///
|
||||
|
@ -2764,6 +2764,10 @@ v8::Handle<v8::Array> TRI_V8PathList (string const& modules) {
|
|||
return scope.Close(result);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- modules initialisation
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief stores the V8 utils functions inside the global variable
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -61,15 +61,28 @@ if test "x$tr_READLINE" = xyes -o "x$tr_READLINE" = xmaybe; then
|
|||
AC_CHECK_LIB([readline], [readline], [READLINE_LIBS="-lreadline" tr_READLINE="yes"], [tr_READLINE="no"])
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([READLINE support])
|
||||
|
||||
if test "x$tr_READLINE" != xyes; then
|
||||
AC_MSG_RESULT([not found])
|
||||
|
||||
if test "x$ch_READLINE" = xyes; then
|
||||
AC_MSG_ERROR([Please install readline support])
|
||||
fi
|
||||
else
|
||||
AC_MSG_RESULT([readline])
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "x$tr_READLINE" = xno; then
|
||||
AC_MSG_ERROR([Please install readline support])
|
||||
elif test "x$tr_READLINE" = xlinenoise; then
|
||||
READLINE_CPPFLAGS="-I${srcdir}/3rdParty/linenoise -DUSE_UTF8"
|
||||
|
||||
AC_MSG_CHECKING([READLINE support])
|
||||
AC_MSG_RESULT([linenoise])
|
||||
|
||||
else
|
||||
AC_MSG_CHECKING([READLINE support])
|
||||
AC_MSG_RESULT([disabled])
|
||||
|
||||
fi
|
||||
|
||||
dnl ----------------------------------------------------------------------------
|
||||
|
@ -91,17 +104,23 @@ main () {
|
|||
}
|
||||
|
||||
_ACEOF
|
||||
AC_MSG_CHECKING([READLINE version])
|
||||
eval "$ac_cpp conftest.$ac_ext" | fgrep "long sdnhg36ed" | awk '{print $4 "." $5}' > conftest.output
|
||||
TRI_READLINE_VERSION=`cat conftest.output`
|
||||
|
||||
if test -z "$TRI_READLINE_VERSION"; then
|
||||
AC_MSG_ERROR([Readline support is not working. Please re-install readline support])
|
||||
fi
|
||||
AC_MSG_CHECKING([READLINE version])
|
||||
eval "$ac_cpp conftest.$ac_ext" | fgrep "long sdnhg36ed" | awk '{print $4 "." $5}' > conftest.output
|
||||
TRI_READLINE_VERSION=`cat conftest.output`
|
||||
|
||||
AC_MSG_RESULT([$TRI_READLINE_VERSION])
|
||||
rm -f conftest*
|
||||
if test -z "$TRI_READLINE_VERSION"; then
|
||||
AC_MSG_ERROR([Readline support is not working. Please re-install readline support])
|
||||
fi
|
||||
|
||||
AC_MSG_RESULT([$TRI_READLINE_VERSION])
|
||||
rm -f conftest*
|
||||
|
||||
elif test "x$tr_READLINE" = xlinenoise; then
|
||||
TRI_READLINE_VERSION="linenoise"
|
||||
|
||||
AC_MSG_CHECKING([READLINE version])
|
||||
AC_MSG_RESULT([$TRI_READLINE_VERSION])
|
||||
fi
|
||||
|
||||
dnl ----------------------------------------------------------------------------
|
||||
|
@ -115,6 +134,9 @@ CPPFLAGS="$SAVE_CPPFLAGS"
|
|||
if test "x$tr_READLINE" = xyes; then
|
||||
CPPFLAGS="$CPPFLAGS -DHAVE_READLINE=1"
|
||||
READLINE_CPPFLAGS="${READLINE_CPPFLAGS} -DTRI_READLINE_VERSION='\"${TRI_READLINE_VERSION}\"'"
|
||||
|
||||
elif test "x$tr_READLINE" = xlinenoise; then
|
||||
READLINE_CPPFLAGS="${READLINE_CPPFLAGS} -DTRI_READLINE_VERSION='\"${TRI_READLINE_VERSION}\"'"
|
||||
fi
|
||||
|
||||
dnl ----------------------------------------------------------------------------
|
||||
|
@ -123,6 +145,16 @@ dnl ----------------------------------------------------------------------------
|
|||
|
||||
AM_CONDITIONAL(ENABLE_READLINE, test "x$tr_READLINE" = xyes)
|
||||
|
||||
if test "x$tr_READLINE" = xyes; then
|
||||
AC_DEFINE_UNQUOTED(TRI_HAVE_READLINE, 1, [true if readline is used])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(ENABLE_LINENOISE, test "x$tr_READLINE" = xlinenoise)
|
||||
|
||||
if test "x$tr_READLINE" = xlinenoise; then
|
||||
AC_DEFINE_UNQUOTED(TRI_HAVE_LINENOISE, 1, [true if linenoise is used])
|
||||
fi
|
||||
|
||||
AC_SUBST(READLINE_CPPFLAGS)
|
||||
AC_SUBST(READLINE_LDFLAGS)
|
||||
AC_SUBST(READLINE_LIBS)
|
||||
|
@ -132,11 +164,19 @@ dnl informational output
|
|||
dnl ----------------------------------------------------------------------------
|
||||
|
||||
if test "x$tr_READLINE" = xyes; then
|
||||
LIB_INFO="$LIB_INFO|READLINE VERSION: ${TRI_READLINE_VERSION}"
|
||||
LIB_INFO="$LIB_INFO|READLINE VERSION: ${TRI_READLINE_VERSION}"
|
||||
|
||||
LIB_INFO="$LIB_INFO|READLINE_CPPLIBS: ${READLINE_CPPLIBS}"
|
||||
LIB_INFO="$LIB_INFO|READLINE_LDLIBS: ${READLINE_LDLIBS}"
|
||||
LIB_INFO="$LIB_INFO|READLINE_CPPFLAGS: ${READLINE_CPPFLAGS}"
|
||||
LIB_INFO="$LIB_INFO|READLINE_LDLIBS: ${READLINE_LDLIBS}"
|
||||
LIB_INFO="$LIB_INFO|READLINE_LIBS: ${READLINE_LIBS}"
|
||||
|
||||
elif test "x$tr_READLINE" = xlinenoise; then
|
||||
LIB_INFO="$LIB_INFO|LINENOISE VERSION: ${TRI_READLINE_VERSION}"
|
||||
|
||||
LIB_INFO="$LIB_INFO|LINENOISE_CPPFLAGS: ${READLINE_CPPFLAGS}"
|
||||
LIB_INFO="$LIB_INFO|LINENOISE_LDLIBS: ${READLINE_LDLIBS}"
|
||||
LIB_INFO="$LIB_INFO|LINENOISE_LIBS: ${READLINE_LIBS}"
|
||||
|
||||
else
|
||||
LIB_INFO="$LIB_INFO|READLINE VERSION: disabled"
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue