1
0
Fork 0

fix UTF-8 console output in Windows

This commit is contained in:
Jan Steemann 2013-10-08 13:12:00 +02:00
parent 46a295ba43
commit fb08211ac9
8 changed files with 201 additions and 95 deletions

View File

@ -7,8 +7,7 @@ break=off
setlocal enableextensions
SET ACTION_DIR=".\js\actions\demo"
SET ACTION_SYS_DIR=".\js\actions\system"
SET ACTION_DIR=".\js\actions"
SET GC=20
SET STARTUP_MOD=".\js\server\modules;.\js\common\modules;.\js\node"
SET STARTUP_DIR=".\js"
@ -16,8 +15,6 @@ SET APP_PATH=".\js\apps"
SET PACKAGE_PATH=".\js\npm"
SET DATABASE_DIR=".\data"
SET HTTP_PORT=tcp://127.0.0.1:8529
SET LOG_LEVEL=info
@ -40,12 +37,12 @@ if NOT EXIST ".\data" (
:: # This indicates abnormal termination.
:: ##################################################################
if EXIST ".\data\lock" goto DEL_LOCK
if EXIST ".\data\LOCK" goto DEL_LOCK
:DEL_LOCK
echo removing lock file
del /F .\data\lock > NUL
if EXIST ".\data\lock" (
del /F .\data\LOCK > NUL
if EXIST ".\data\LOCK" (
echo =======================================================================================
echo ERROR: There appears to be a lock file which is in use. This is generally caused
echo by starting a second server instance before the first instance has terminated.
@ -70,7 +67,7 @@ SET CMD=%CMD% --database.directory %DATABASE_DIR%
SET CMD=%CMD% --server.disable-authentication true
SET CMD=%CMD% --log.level %LOG_LEVEL%
SET CMD=%CMD% --log.severity human
SET CMD=%CMD% --javascript.action-directory %ACTION_SYS_DIR%
SET CMD=%CMD% --javascript.action-directory %ACTION_DIR%
SET CMD=%CMD% --javascript.modules-path %STARTUP_MOD%
SET CMD=%CMD% --javascript.startup-directory %STARTUP_DIR%
SET CMD=%CMD% --javascript.app-path %APP_PATH%
@ -81,14 +78,12 @@ SET CMD=%CMD% --scheduler.threads 4
:: SET CMD=%CMD% --database.maximal-journal-size 1048576
SET CMD=%CMD% --console
SET CMD=%CMD% %*
echo starting arangod.exe in server mode
echo with %CMD%
arangod.exe %CMD%
goto END
:END

View File

@ -0,0 +1,41 @@
@echo off
:: #################################################################
:: # script to start the foxx manager in windows
:: #################################################################
cls
break=off
setlocal enableextensions
SET STARTUP_MOD=".\js\client\modules;.\js\common\modules;.\js\node"
SET STARTUP_DIR=".\js"
SET PACKAGE_PATH=".\js\npm"
SET HTTP_PORT=tcp://127.0.0.1:8529
SET LOG_LEVEL=info
:START_ARANGO
:: ##################################################################
:: # set the command line parameters
:: # If you wish to start the shell without a connection to an
:: # server, please change the the command
:: # SET CMD=%CMD% --server.endpoint %HTTP_PORT%
:: # to
:: # SET CMD=%CMD% --server.endpoint none
:: ##################################################################
SET CMD=
SET CMD=%CMD% --server.endpoint %HTTP_PORT%
SET CMD=%CMD% --server.disable-authentication true
SET CMD=%CMD% --log.level %LOG_LEVEL%
SET CMD=%CMD% --javascript.startup-directory %STARTUP_DIR%
SET CMD=%CMD% --javascript.modules-path %STARTUP_MOD%
SET CMD=%CMD% --javascript.package-path %PACKAGE_PATH%
SET CMD=%CMD% --javascript.execute-string "require(\"org/arangodb/foxx/manager\").run(ARGUMENTS);"
SET CMD=%CMD% %*
echo starting arangosh.exe
echo with %CMD%
arangosh.exe %CMD%

View File

@ -8,7 +8,6 @@ setlocal enableextensions
SET ACTION_DIR=".\js\actions"
SET GC=20
SET STARTUP_MOD=".\js\server\modules;.\js\common\modules;.\js\node"
SET STARTUP_DIR=".\js"
SET APP_PATH=".\js\apps"
@ -38,12 +37,12 @@ if NOT EXIST ".\data" (
:: # This indicates abnormal termination.
:: ##################################################################
if EXIST ".\data\lock" goto DEL_LOCK
if EXIST ".\data\LOCK" goto DEL_LOCK
:DEL_LOCK
echo removing lock file
del /F .\data\lock > NUL
if EXIST ".\data\lock" (
del /F .\data\LOCK > NUL
if EXIST ".\data\LOCK" (
echo =======================================================================================
echo ERROR: There appears to be a lock file which is in use. This is generally caused
echo by starting a second server instance before the first instance has terminated.
@ -78,14 +77,11 @@ SET CMD=%CMD% --scheduler.threads 4
:: the default size is 32M change this if required - especially in the 32 bit version
:: SET CMD=%CMD% --database.maximal-journal-size 1048576
SET CMD=%CMD% %*
echo starting arangod.exe in server mode
echo with %CMD%
arangod.exe %CMD%
goto END
:END

View File

@ -6,16 +6,10 @@ cls
break=off
setlocal enableextensions
SET ACTION_DIR=".\js\actions\demo"
SET ACTION_SYS_DIR=".\js\actions\system"
SET GC=20
SET STARTUP_MOD=".\js\client\modules;.\js\common\modules;.\js\node"
SET STARTUP_DIR=".\js"
SET PACKAGE_PATH=".\js\npm"
SET HTTP_PORT=tcp://127.0.0.1:8529
SET LOG_LEVEL=info
@ -38,15 +32,9 @@ SET CMD=%CMD% --javascript.startup-directory %STARTUP_DIR%
SET CMD=%CMD% --javascript.modules-path %STARTUP_MOD%
SET CMD=%CMD% --javascript.package-path %PACKAGE_PATH%
SET CMD=%CMD% %*
echo starting arangosh.exe
echo with %CMD%
arangosh.exe %CMD%
goto END
:END

View File

@ -8,15 +8,12 @@ setlocal enableextensions
SET ACTION_DIR=".\js\actions"
SET GC=20
SET STARTUP_MOD=".\js\server\modules;.\js\common\modules;.\js\node"
SET STARTUP_DIR=".\js"
SET APP_PATH=".\js\apps"
SET PACKAGE_PATH=".\js\npm"
SET DATABASE_DIR=".\data"
SET HTTP_PORT=tcp://127.0.0.1:8529
SET LOG_LEVEL=info
@ -39,12 +36,12 @@ if NOT EXIST ".\data" (
:: # This indicates abnormal termination.
:: ##################################################################
if EXIST ".\data\lock" goto DEL_LOCK
if EXIST ".\data\LOCK" goto DEL_LOCK
:DEL_LOCK
echo removing lock file
del /F .\data\lock > NUL
if EXIST ".\data\lock" (
del /F .\data\LOCK > NUL
if EXIST ".\data\LOCK" (
echo =======================================================================================
echo ERROR: There appears to be a lock file which is in use. This is generally caused
echo by starting a second server instance before the first instance has terminated.
@ -81,14 +78,12 @@ SET CMD=%CMD% --scheduler.threads 4
SET CMD=%CMD% --console
SET CMD=%CMD% --upgrade
SET CMD=%CMD% %*
echo starting arangod.exe in server mode
echo with %CMD%
arangod.exe %CMD%
goto END
:END

View File

@ -392,7 +392,7 @@ void ArangoClient::parse (ProgramOptions& options,
// no password given on command-line
if (! _hasPassword) {
usleep(10 * 1000);
cout << "Please specify a password: " << flush;
printContinuous("Please specify a password: ");
// now prompt for it
#ifdef TRI_HAVE_TERMIOS_H
@ -403,11 +403,47 @@ void ArangoClient::parse (ProgramOptions& options,
#else
getline(cin, _password);
#endif
cout << "\n";
printLine("");
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief print a string and a newline to stderr
////////////////////////////////////////////////////////////////////////////////
void ArangoClient::printErrLine (const string& s) {
#ifdef _WIN32
// no, we can use std::cerr as this doesn't support UTF-8 on Windows
fprintf(stderr, "%s\r\n", s.c_str());
#else
fprintf(stderr, "%s\n", s.c_str());
#endif
}
////////////////////////////////////////////////////////////////////////////////
/// @brief print a string and a newline to stdout
////////////////////////////////////////////////////////////////////////////////
void ArangoClient::printLine (const string& s) {
#ifdef _WIN32
// no, we can use std::cout as this doesn't support UTF-8 on Windows
fprintf(stdout, "%s\r\n", s.c_str());
#else
fprintf(stdout, "%s\n", s.c_str());
#endif
}
////////////////////////////////////////////////////////////////////////////////
/// @brief print a string to stdout, without a newline
////////////////////////////////////////////////////////////////////////////////
void ArangoClient::printContinuous (const string& s) {
// no, we can use std::cout as this doesn't support UTF-8 on Windows
fprintf(stdout, "%s", s.c_str());
fflush(stdout);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief starts pager
////////////////////////////////////////////////////////////////////////////////
@ -501,11 +537,15 @@ void ArangoClient::internalPrint (const char* format, const char* str) {
void ArangoClient::openLog () {
if (! _logFile.empty()) {
_log = fopen(_logFile.c_str(), "w");
ostringstream s;
if (_log == 0) {
cerr << "Cannot open file '" << _logFile << "' for logging." << endl;
s << "Cannot open file '" << _logFile << "' for logging.";
printErrLine(s.str());
}
else {
cout << "Logging input and output to '" << _logFile << "'." << endl;
s << "Logging input and output to '" << _logFile << "'.";
printLine(s.str());
}
}
}
@ -527,11 +567,14 @@ void ArangoClient::closeLog () {
void ArangoClient::printWelcomeInfo () {
if (_usePager) {
cout << "Using pager '" << _outputPager << "' for output buffering." << endl;
ostringstream s;
s << "Using pager '" << _outputPager << "' for output buffering.";
printLine(s.str());
}
if (_prettyPrint) {
cout << "Pretty printing values." << endl;
printLine("Pretty printing values.");
}
}
@ -541,7 +584,8 @@ void ArangoClient::printWelcomeInfo () {
void ArangoClient::printByeBye () {
if (! _quiet) {
cout << "<ctrl-D>" << endl << TRI_BYE_MESSAGE << endl;
printLine("<ctrl-D>");
printLine(TRI_BYE_MESSAGE);
}
}

View File

@ -211,6 +211,24 @@ namespace triagens {
char* argv[],
string const& initFilename);
////////////////////////////////////////////////////////////////////////////////
/// @brief print a string and a newline to stderr, necessary for Windows
////////////////////////////////////////////////////////////////////////////////
void printErrLine (const std::string&);
////////////////////////////////////////////////////////////////////////////////
/// @brief print a string and a newline to stdout, necessary for Windows
////////////////////////////////////////////////////////////////////////////////
void printLine (const std::string&);
////////////////////////////////////////////////////////////////////////////////
/// @brief print a string to stdout, without a newline, necessary for Windows
////////////////////////////////////////////////////////////////////////////////
void printContinuous (const std::string&);
////////////////////////////////////////////////////////////////////////////////
/// @brief starts pager
////////////////////////////////////////////////////////////////////////////////

View File

@ -294,9 +294,9 @@ static v8::Handle<v8::Value> JS_ImportCsvFile (v8::Arguments const& argv) {
if (ih.importDelimited(collectionName, fileName, ImportHelper::CSV)) {
v8::Handle<v8::Object> result = v8::Object::New();
result->Set(v8::String::New("lines"), v8::Integer::New(ih.getReadLines()));
result->Set(v8::String::New("created"), v8::Integer::New(ih.getImportedLines()));
result->Set(v8::String::New("errors"), v8::Integer::New(ih.getErrorLines()));
result->Set(v8::String::New("lines"), v8::Integer::New((int32_t) ih.getReadLines()));
result->Set(v8::String::New("created"), v8::Integer::New((int32_t) ih.getImportedLines()));
result->Set(v8::String::New("errors"), v8::Integer::New((int32_t) ih.getErrorLines()));
return scope.Close(result);
}
@ -340,9 +340,9 @@ static v8::Handle<v8::Value> JS_ImportJsonFile (v8::Arguments const& argv) {
if (ih.importJson(collectionName, fileName)) {
v8::Handle<v8::Object> result = v8::Object::New();
result->Set(v8::String::New("lines"), v8::Integer::New(ih.getReadLines()));
result->Set(v8::String::New("created"), v8::Integer::New(ih.getImportedLines()));
result->Set(v8::String::New("errors"), v8::Integer::New(ih.getErrorLines()));
result->Set(v8::String::New("lines"), v8::Integer::New((int32_t) ih.getReadLines()));
result->Set(v8::String::New("created"), v8::Integer::New((int32_t) ih.getImportedLines()));
result->Set(v8::String::New("errors"), v8::Integer::New((int32_t) ih.getErrorLines()));
return scope.Close(result);
}
@ -543,9 +543,11 @@ static v8::Handle<v8::Value> ClientConnection_ConstructorCallback (v8::Arguments
V8ClientConnection* connection = CreateConnection();
if (connection->isConnected() && connection->getLastHttpReturnCode() == HttpResponse::OK) {
cout << "Connected to ArangoDB '" << BaseClient.endpointServer()->getSpecification()
<< "', version " << connection->getVersion() << ", database '" << BaseClient.databaseName()
<< "', username: '" << BaseClient.username() << "'" << endl;
ostringstream s;
s << "Connected to ArangoDB '" << BaseClient.endpointServer()->getSpecification()
<< "', version " << connection->getVersion() << ", database '" << BaseClient.databaseName()
<< "', username: '" << BaseClient.username() << "'";
BaseClient.printLine(s.str());
}
else {
string errorMessage = "Could not connect. Error message: " + connection->getErrorMessage();
@ -586,7 +588,7 @@ static v8::Handle<v8::Value> ClientConnection_reconnect (v8::Arguments const& ar
string password;
if (argv.Length() < 4) {
cout << "Please specify a password: " << flush;
BaseClient.printContinuous("Please specify a password: ");
// now prompt for it
#ifdef TRI_HAVE_TERMIOS_H
@ -597,7 +599,7 @@ static v8::Handle<v8::Value> ClientConnection_reconnect (v8::Arguments const& ar
#else
getline(cin, password);
#endif
cout << "\n";
BaseClient.printLine("");
}
else {
password = TRI_ObjectToString(argv[3]);
@ -631,9 +633,12 @@ static v8::Handle<v8::Value> ClientConnection_reconnect (v8::Arguments const& ar
V8ClientConnection* newConnection = CreateConnection();
if (newConnection->isConnected() && newConnection->getLastHttpReturnCode() == HttpResponse::OK) {
cout << "Connected to ArangoDB '" << BaseClient.endpointServer()->getSpecification()
<< "' version: " << newConnection->getVersion() << ", database: '" << BaseClient.databaseName()
<< "', username: '" << BaseClient.username() << "'" << endl;
ostringstream s;
s << "Connected to ArangoDB '" << BaseClient.endpointServer()->getSpecification()
<< "' version: " << newConnection->getVersion() << ", database: '" << BaseClient.databaseName()
<< "', username: '" << BaseClient.username() << "'";
BaseClient.printLine(s.str());
argv.Holder()->SetInternalField(SLOT_CLASS, v8::External::New(newConnection));
@ -653,7 +658,10 @@ static v8::Handle<v8::Value> ClientConnection_reconnect (v8::Arguments const& ar
return scope.Close(v8::True());
}
else {
cerr << "Could not connect to endpoint '" << BaseClient.endpointString() << "', username: '" << BaseClient.username() << "'" << endl;
ostringstream s;
s << "Could not connect to endpoint '" << BaseClient.endpointString() <<
"', username: '" << BaseClient.username() << "'";
BaseClient.printErrLine(s.str());
string errorMsg = "could not connect";
if (newConnection->getErrorMessage() != "") {
@ -1073,7 +1081,7 @@ static v8::Handle<v8::Value> ClientConnection_getEndpoint (v8::Arguments const&
}
const string endpoint = BaseClient.endpointString();
return scope.Close(v8::String::New(endpoint.c_str(), endpoint.size()));
return scope.Close(v8::String::New(endpoint.c_str(), (int) endpoint.size()));
}
////////////////////////////////////////////////////////////////////////////////
@ -1250,7 +1258,7 @@ static void RunShell (v8::Handle<v8::Context> context, bool promptError) {
console.open(BaseClient.autoComplete());
cout << endl;
BaseClient.printLine("");
while (true) {
// set up prompts
@ -1352,7 +1360,7 @@ static void RunShell (v8::Handle<v8::Context> context, bool promptError) {
// command failed
string exception(TRI_StringifyV8Exception(&tryCatch));
cerr << exception;
BaseClient.printErrLine(exception);
BaseClient.log("%s", exception.c_str());
// this will change the prompt for the next round
@ -1360,7 +1368,7 @@ static void RunShell (v8::Handle<v8::Context> context, bool promptError) {
}
BaseClient.stopPager();
cout << endl;
BaseClient.printLine("");
BaseClient.log("%s\n", "");
// make sure the last command result makes it into the log file
@ -1369,7 +1377,7 @@ static void RunShell (v8::Handle<v8::Context> context, bool promptError) {
console.close();
cout << endl;
BaseClient.printLine("");
BaseClient.printByeBye();
}
@ -1399,7 +1407,7 @@ static bool RunUnitTests (v8::Handle<v8::Context> context) {
TRI_ExecuteJavaScriptString(context, v8::String::New(input), name, true);
if (tryCatch.HasCaught()) {
cerr << TRI_StringifyV8Exception(&tryCatch);
BaseClient.printErrLine(TRI_StringifyV8Exception(&tryCatch));
ok = false;
}
else {
@ -1424,7 +1432,10 @@ static bool RunScripts (v8::Handle<v8::Context> context,
for (size_t i = 0; i < scripts.size(); ++i) {
if (! FileUtils::exists(scripts[i])) {
cerr << "error: Javascript file not found: '" << scripts[i].c_str() << "'" << endl;
ostringstream s;
s << "error: Javascript file not found: '" << scripts[i].c_str() << "'";
BaseClient.printErrLine(s.str());
BaseClient.log("error: Javascript file not found: '%s'\n", scripts[i].c_str());
ok = false;
break;
@ -1439,8 +1450,8 @@ static bool RunScripts (v8::Handle<v8::Context> context,
if (tryCatch.HasCaught()) {
string exception(TRI_StringifyV8Exception(&tryCatch));
BaseClient.printErrLine(exception);
cerr << exception << endl;
BaseClient.log("%s\n", exception.c_str());
ok = false;
break;
@ -1464,14 +1475,14 @@ static bool RunString (v8::Handle<v8::Context> context,
bool ok = true;
v8::Handle<v8::Value> result = TRI_ExecuteJavaScriptString(context,
v8::String::New(script.c_str(), script.size()),
v8::String::New(script.c_str(), (int) script.size()),
v8::String::New("(command-line)"),
false);
if (tryCatch.HasCaught()) {
string exception(TRI_StringifyV8Exception(&tryCatch));
cerr << exception << endl;
BaseClient.printErrLine(exception);
BaseClient.log("%s\n", exception.c_str());
ok = false;
}
@ -1516,7 +1527,7 @@ static bool RunJsLint (v8::Handle<v8::Context> context) {
TRI_ExecuteJavaScriptString(context, v8::String::New(input), name, true);
if (tryCatch.HasCaught()) {
cerr << TRI_StringifyV8Exception(&tryCatch);
BaseClient.printErrLine(TRI_StringifyV8Exception(&tryCatch));
ok = false;
}
else {
@ -1642,7 +1653,11 @@ int main (int argc, char* argv[]) {
BaseClient.createEndpoint();
if (BaseClient.endpointServer() == 0) {
cerr << "invalid value for --server.endpoint ('" << BaseClient.endpointString() << "')" << endl;
ostringstream s;
s << "invalid value for --server.endpoint ('" << BaseClient.endpointString() << "')";
BaseClient.printErrLine(s.str());
TRI_EXIT_FUNCTION(EXIT_FAILURE,NULL);
}
@ -1664,7 +1679,7 @@ int main (int argc, char* argv[]) {
v8::Persistent<v8::Context> context = v8::Context::New(0, global);
if (context.IsEmpty()) {
cerr << "cannot initialize V8 engine" << endl;
BaseClient.printErrLine("cannot initialize V8 engine");
TRI_EXIT_FUNCTION(EXIT_FAILURE,NULL);
}
@ -1765,7 +1780,7 @@ int main (int argc, char* argv[]) {
}
// not sure about the code page
//SetConsoleOutputCP(65001);
SetConsoleOutputCP(65001);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), greenColour);
printf(" ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), redColour);
@ -1816,7 +1831,7 @@ int main (int argc, char* argv[]) {
z = "";
}
cout << endl;
BaseClient.printLine("");
printf("%s %s _ %s\n", g, r, z);
printf("%s __ _ _ __ __ _ _ __ __ _ ___ %s ___| |__ %s\n", g, r, z);
@ -1826,10 +1841,15 @@ int main (int argc, char* argv[]) {
printf("%s |___/ %s %s\n", g, r, z);
#endif
BaseClient.printLine("");
cout << endl << "Welcome to arangosh " << TRI_VERSION_FULL << ". Copyright (c) triAGENS GmbH" << endl;
ostringstream s;
s << "Welcome to arangosh " << TRI_VERSION_FULL << ". Copyright (c) triAGENS GmbH";
BaseClient.printLine(s.str());
ostringstream info;
info << "Using ";
#ifdef TRI_V8_VERSION
info << "Google V8 " << TRI_V8_VERSION << " JavaScript engine";
@ -1845,27 +1865,36 @@ int main (int argc, char* argv[]) {
info << ", ICU " << TRI_ICU_VERSION;
#endif
cout << "Using " << info.str() << endl << endl;
BaseClient.printLine(info.str());
BaseClient.printLine("");
BaseClient.printWelcomeInfo();
if (useServer) {
if (ClientConnection->isConnected() && ClientConnection->getLastHttpReturnCode() == HttpResponse::OK) {
cout << "Connected to ArangoDB '" << BaseClient.endpointString()
<< "' version: " << ClientConnection->getVersion() << ", database: '" << BaseClient.databaseName()
<< "', username: '" << BaseClient.username() << "'" << endl;
ostringstream is;
is << "Connected to ArangoDB '" << BaseClient.endpointString()
<< "' version: " << ClientConnection->getVersion() << ", database: '" << BaseClient.databaseName()
<< "', username: '" << BaseClient.username() << "'";
BaseClient.printLine(is.str());
}
else {
cerr << "Could not connect to endpoint '" << BaseClient.endpointString()
<< "', database: '" << BaseClient.databaseName()
<< "', username: '" << BaseClient.username() << "'" << endl;
ostringstream is;
is << "Could not connect to endpoint '" << BaseClient.endpointString()
<< "', database: '" << BaseClient.databaseName()
<< "', username: '" << BaseClient.username() << "'";
BaseClient.printErrLine(is.str());
if (ClientConnection->getErrorMessage() != "") {
cerr << "Error message '" << ClientConnection->getErrorMessage() << "'" << endl;
ostringstream is2;
is2 << "Error message '" << ClientConnection->getErrorMessage() << "'";
BaseClient.printErrLine(is2.str());
}
promptError = true;
}
cout << endl;
BaseClient.printLine("");
}
}
@ -1943,10 +1972,10 @@ int main (int argc, char* argv[]) {
// create arguments
// .............................................................................
v8::Handle<v8::Array> p = v8::Array::New(positionals.size());
v8::Handle<v8::Array> p = v8::Array::New((int) positionals.size());
for (size_t i = 0; i < positionals.size(); ++i) {
p->Set(i, v8::String::New(positionals[i].c_str()));
for (uint32_t i = 0; i < positionals.size(); ++i) {
p->Set(i, v8::String::New(positionals[i].c_str(), (int) positionals[i].size()));
}
TRI_AddGlobalVariableVocbase(context, "ARGUMENTS", p);