summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorU-ELIOT-019992DFC\Administrator <Administrator@eliot-019992dfc.(none)>2009-02-10 13:45:30 -0500
committerU-ELIOT-019992DFC\Administrator <Administrator@eliot-019992dfc.(none)>2009-02-10 13:45:30 -0500
commit1b6151f37bac33e50869ebaab67ba625be29cc49 (patch)
treea58c2038214b265f1a7031e502e3ef2f86e732e5
parent015bbe731619fcf55032af37df98d39dd24ef686 (diff)
downloadmongo-1b6151f37bac33e50869ebaab67ba625be29cc49.tar.gz
make dbshell not require readline
-rw-r--r--SConstruct4
-rw-r--r--shell/MongoJS.cpp6
-rw-r--r--shell/dbshell.cpp51
3 files changed, 51 insertions, 10 deletions
diff --git a/SConstruct b/SConstruct
index a7e111cc183..f7ee3458e24 100644
--- a/SConstruct
+++ b/SConstruct
@@ -505,7 +505,9 @@ if release and ( ( darwin and force64 ) or linux64 ):
shellEnv["LIBS"] = env["LIBS_CLEAN"]
shellEnv["SLIBS"] = ""
-shellEnv.Append( LIBS=[ "v8" , "readline" ] )
+shellEnv.Append( LIBS=[ "v8" ] )
+if not windows:
+ shellEnv.Append( ["readline" ] )
shellEnv.JSConcat( "shell/mongo.jsall" , Glob( "shell/*.js" ) )
shellEnv.JSHeader( "shell/mongo.jsall" )
diff --git a/shell/MongoJS.cpp b/shell/MongoJS.cpp
index 8184e80db63..3fbdc999ca1 100644
--- a/shell/MongoJS.cpp
+++ b/shell/MongoJS.cpp
@@ -260,7 +260,11 @@ BSONObj v8ToMongo( v8::Handle<v8::Object> o ){
return b.obj();
}
+#ifdef _WIN32
+#define GETNS char * ns = new char[args[0]->ToString()->Utf8Length()]; args[0]->ToString()->WriteUtf8( ns );
+#else
#define GETNS char ns[args[0]->ToString()->Utf8Length()]; args[0]->ToString()->WriteUtf8( ns );
+#endif
DBClientConnection * getConnection( const Arguments& args ){
Local<External> c = External::Cast( *(args.This()->Get( CONN_STRING )) );
@@ -316,7 +320,7 @@ v8::Handle<v8::Value> mongoInsert(const v8::Arguments& args){
v8::Handle<v8::Object> in = args[1]->ToObject();
if ( ! in->Has( String::New( "_id" ) ) ){
- v8::Handle<v8::Value> argv[0];
+ v8::Handle<v8::Value> argv[1];
in->Set( String::New( "_id" ) , getObjectIdCons()->NewInstance( 0 , argv ) );
}
diff --git a/shell/dbshell.cpp b/shell/dbshell.cpp
index 67750b857a9..7cbe5bf32ef 100644
--- a/shell/dbshell.cpp
+++ b/shell/dbshell.cpp
@@ -2,8 +2,15 @@
#include <v8.h>
+#ifdef _WIN32
+#else
+#define USE_READLINE
+#endif
+
+#ifdef USE_READLINE
#include <readline/readline.h>
#include <readline/history.h>
+#endif
#include "ShellUtils.h"
#include "MongoJS.h"
@@ -11,8 +18,36 @@
#include "mongo.jsh"
-void quitNicely( int sig ){
+void shellHistoryInit(){
+#ifdef USE_READLINE
+ using_history();
+ read_history( ".dbshell" );
+#endif
+}
+void shellHistoryDone(){
+#ifdef USE_READLINE
write_history( ".dbshell" );
+#endif
+}
+void shellHistoryAdd( const char * line ){
+ if ( strlen(line) == 0 )
+ return;
+#ifdef USE_READLINE
+ add_history( line );
+#endif
+}
+char * shellReadline( const char * prompt ){
+#ifdef USE_READLINE
+ return readline( "> " );
+#else
+ printf( "> " );
+ char * buf = new char[1024];
+ return fgets( buf , 1024 , stdin );
+#endif
+}
+
+void quitNicely( int sig ){
+ shellHistoryDone();
exit(0);
}
@@ -22,6 +57,7 @@ void quitAbruptly( int sig ) {
}
void setupSignals() {
+#ifndef _WIN32
signal( SIGINT , quitNicely );
signal( SIGTERM , quitNicely );
signal( SIGPIPE , quitNicely ); // Maybe just log and continue?
@@ -29,6 +65,7 @@ void setupSignals() {
signal( SIGSEGV , quitAbruptly );
signal( SIGBUS , quitAbruptly );
signal( SIGFPE , quitAbruptly );
+#endif
}
string fixHost( string url , string host , string port ){
@@ -242,9 +279,8 @@ int main(int argc, char* argv[]) {
if ( runShell ){
MongodScope s;
-
- using_history();
- read_history( ".dbshell" );
+
+ shellHistoryInit();
cout << "type \"help\" for help" << endl;
@@ -252,7 +288,7 @@ int main(int argc, char* argv[]) {
while ( 1 ){
- char * line = readline( "> " );
+ char * line = shellReadline( "> " );
if ( ! line || ( strlen(line) == 4 && strstr( line , "exit" ) ) ){
cout << "bye" << endl;
@@ -281,11 +317,10 @@ int main(int argc, char* argv[]) {
true);
- if ( strlen( line ) )
- add_history( line );
+ shellHistoryAdd( line );
}
- write_history( ".dbshell" );
+ shellHistoryDone();
}
return 0;