diff options
author | Aaron <aaron@10gen.com> | 2009-02-10 14:04:09 -0500 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2009-02-10 14:04:09 -0500 |
commit | 975682a74f1163f2a59d62fa7c55a0f96bd50055 (patch) | |
tree | 86c1b3a9bc6e4cd96ba436054ac967028888154f | |
parent | 565d3742839561836424443f95c951005a6030d8 (diff) | |
parent | d71851a4140e03331f8c1c4bdee896dfd7e3c7d0 (diff) | |
download | mongo-975682a74f1163f2a59d62fa7c55a0f96bd50055.tar.gz |
Merge branch 'master' of ssh://aaron@git.10gen.com/data/gitroot/p
-rw-r--r-- | SConstruct | 4 | ||||
-rw-r--r-- | shell/MongoJS.cpp | 6 | ||||
-rw-r--r-- | shell/dbshell.cpp | 51 |
3 files changed, 51 insertions, 10 deletions
diff --git a/SConstruct b/SConstruct index a7e111cc183..8320729ebe2 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( LIBS=["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; |