[Rinside-commits] r219 - in pkg: . inst inst/examples/wt inst/include src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Dec 7 06:47:21 CET 2011


Author: edd
Date: 2011-12-07 06:47:21 +0100 (Wed, 07 Dec 2011)
New Revision: 219

Modified:
   pkg/.Rbuildignore
   pkg/ChangeLog
   pkg/DESCRIPTION
   pkg/cleanup
   pkg/doxyfile
   pkg/inst/NEWS
   pkg/inst/THANKS
   pkg/inst/examples/wt/Makefile
   pkg/inst/include/RInsideCommon.h
   pkg/src/RInside.cpp
Log:
apply James Bates' fix for Windows
couply small related cleanups
update Version: to 0.2.5 
could be read for release or may a small tweak or two


Modified: pkg/.Rbuildignore
===================================================================
--- pkg/.Rbuildignore	2011-12-05 02:58:52 UTC (rev 218)
+++ pkg/.Rbuildignore	2011-12-07 05:47:21 UTC (rev 219)
@@ -3,3 +3,11 @@
 inst/doc/man
 inst/doc
 inst/lib
+inst/examples/qt/Makefile
+inst/examples/qt/link.sh
+inst/examples/qt/moc_qtdensity.cpp
+inst/examples/qt/qtdensity
+inst/examples/standard/rinside_sample11
+inst/examples/wt/extkitchen.css
+inst/examples/wt/resources -> /usr/share/Wt/resources/
+inst/examples/wt/wtdensity

Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2011-12-05 02:58:52 UTC (rev 218)
+++ pkg/ChangeLog	2011-12-07 05:47:21 UTC (rev 219)
@@ -1,3 +1,19 @@
+2011-12-06  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/RInside.cpp: Applied (a slightly simpler versions of) a patch
+	by James Bates which restores RInside on Windows -- at long last!
+
+	* inst/include/RInsideCommon.h: Define #Win32 in #WIN32 is set so
+	that we get some symbols from Rembedded.h
+
+	* inst/THANKS: Add James Bates for help with RInside on Windows
+	
+	* doxyfile: Add inst/examples/wt to example path
+
+	* cleanup: Some fixes ensuring qt and wt example can be cleaned
+	
+	* .Rbuildignore: Add some local files from qt and wt examples
+
 2011-12-04  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/examples/wt/wtdensity.cpp: bandwidth value capped at 200 like qt

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2011-12-05 02:58:52 UTC (rev 218)
+++ pkg/DESCRIPTION	2011-12-07 05:47:21 UTC (rev 219)
@@ -1,6 +1,6 @@
 Package: RInside
 Title: C++ classes to embed R in C++ applications
-Version: 0.2.4
+Version: 0.2.5
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois
 Maintainer: Dirk Eddelbuettel and Romain Francois <RomainAndDirk at r-enthusiasts.com>

Modified: pkg/cleanup
===================================================================
--- pkg/cleanup	2011-12-05 02:58:52 UTC (rev 218)
+++ pkg/cleanup	2011-12-07 05:47:21 UTC (rev 219)
@@ -4,6 +4,6 @@
 
 cd inst/examples/standard && make clean && cd -
 cd inst/examples/mpi && make clean && cd -
-cd inst/examples/qt && make clean && cd -
+cd inst/examples/qt && qmake && make clean && cd -
 cd inst/examples/wt && make clean && cd -
 

Modified: pkg/doxyfile
===================================================================
--- pkg/doxyfile	2011-12-05 02:58:52 UTC (rev 218)
+++ pkg/doxyfile	2011-12-07 05:47:21 UTC (rev 219)
@@ -697,7 +697,10 @@
 # directories that contain example code fragments that are included (see 
 # the \include command).
 
-EXAMPLE_PATH           = src/examples/standard src/examples/mpi src/examples/qt
+EXAMPLE_PATH           = src/examples/standard \
+		         src/examples/mpi \
+			 src/examples/qt \
+			 src/examples/wt
 
 # If the value of the EXAMPLE_PATH tag contains directories, you can use the 
 # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 

Modified: pkg/inst/NEWS
===================================================================
--- pkg/inst/NEWS	2011-12-05 02:58:52 UTC (rev 218)
+++ pkg/inst/NEWS	2011-12-07 05:47:21 UTC (rev 219)
@@ -1,5 +1,10 @@
 0.2.5   20xx-yy-zz
 
+   o    Applied (somewhat simplified) patch by James Bates which restores
+        RInside to working on Windows -- with a big Thank You! to James for
+        fixing a long-standing bug we inadvertendly introduced right after
+        0.2.0 almost two years ago
+
    o    New example embedding R inside a Wt (aka Webtoolkit, pronounced 
         'witty') application, mirroring the previous Qt application
 

Modified: pkg/inst/THANKS
===================================================================
--- pkg/inst/THANKS	2011-12-05 02:58:52 UTC (rev 218)
+++ pkg/inst/THANKS	2011-12-07 05:47:21 UTC (rev 219)
@@ -8,3 +8,4 @@
 Richard Holbrey         for initial help with the the Windows build 
 Jianping Hua            for contributing two MPI-based examples
 Murray Stokely		for a patch regarding timing of Rcpp autoloads
+James Bates		for a patch restoring RInside on Windows

Modified: pkg/inst/examples/wt/Makefile
===================================================================
--- pkg/inst/examples/wt/Makefile	2011-12-05 02:58:52 UTC (rev 218)
+++ pkg/inst/examples/wt/Makefile	2011-12-07 05:47:21 UTC (rev 219)
@@ -52,4 +52,4 @@
 			./wtdensity --docroot ".;/resources,/tmp" --http-addr 127.0.0.1 --http-port 8080
 
 clean:
-			rm wtdensity
\ No newline at end of file
+			rm -f wtdensity resources

Modified: pkg/inst/include/RInsideCommon.h
===================================================================
--- pkg/inst/include/RInsideCommon.h	2011-12-05 02:58:52 UTC (rev 218)
+++ pkg/inst/include/RInsideCommon.h	2011-12-07 05:47:21 UTC (rev 219)
@@ -1,6 +1,8 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
 // RInsideCommon.h: R/C++ interface class library -- Easier R embedding into C++
 //
-// Copyright (C) 2010        Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of RInside.
 //
@@ -28,6 +30,13 @@
 
 #include <Rcpp.h>
 
+#ifdef WIN32
+  #ifndef Win32
+    // needed for parts of Rembedded.h
+    #define Win32
+  #endif
+#endif
+
 #include <Rembedded.h>
 #ifndef WIN32
 #define R_INTERFACE_PTRS
@@ -40,7 +49,7 @@
 // simple logging help
 inline void logTxtFunction(const char* file, const int line, const char* expression, const bool verbose) {
     if (verbose) {
-	std::cout << file << ":" << line << " expression: " << expression << std::endl;
+        std::cout << file << ":" << line << " expression: " << expression << std::endl;
     }
 }
 

Modified: pkg/src/RInside.cpp
===================================================================
--- pkg/src/RInside.cpp	2011-12-05 02:58:52 UTC (rev 218)
+++ pkg/src/RInside.cpp	2011-12-07 05:47:21 UTC (rev 219)
@@ -1,9 +1,9 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
 //
 // RInside.cpp: R/C++ interface class library -- Easier R embedding into C++
 //
 // Copyright (C) 2009        Dirk Eddelbuettel
-// Copyright (C) 2010        Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of RInside.
 //
@@ -25,7 +25,7 @@
 
 RInside* RInside::instance_ = 0 ;
 
-#include <sys/time.h>		// gettimeofday
+#include <sys/time.h>           // gettimeofday
 
 bool verbose = false;
 const char *programName = "RInside";
@@ -36,7 +36,7 @@
     extern int optind;
 #endif
 
-RInside::~RInside() {		// now empty as MemBuf is internal
+RInside::~RInside() {           // now empty as MemBuf is internal
     logTxt("RInside::dtor BEGIN", verbose);
     R_dot_Last();
     R_RunExitFinalizers();
@@ -52,12 +52,45 @@
 
 RInside::RInside() 
 #ifdef RINSIDE_CALLBACKS 
-	: callbacks(0)
+    : callbacks(0)
 #endif
 {
     initialize( 0, 0, false );
 }
 
+#ifdef WIN32
+static int myReadConsole(const char *prompt, char *buf, int len, int addtohistory) {
+    fputs(prompt, stdout);
+    fflush(stdout);
+    if (fgets(buf, len, stdin)) 
+        return 1;
+    else 
+        return 0;
+}
+ 
+static void myWriteConsole(const char *buf, int len) {
+     Rprintf("%s", buf);
+}
+ 
+static void myCallBack() {
+    /* called during i/o, eval, graphics in ProcessEvents */
+}
+ 
+static void myBusy(int which) {
+    /* set a busy cursor ... if which = 1, unset if which = 0 */
+}
+ 
+void myAskOk(const char *info) {
+ 
+}
+
+int myAskYesNoCancel(const char *question) {
+    const int yes = 1;
+    return yes;
+}
+ 
+#endif
+
 RInside::RInside(const int argc, const char* const argv[], const bool loadRcpp)
 #ifdef RINSIDE_CALLBACKS 
 : callbacks(0)
@@ -71,34 +104,34 @@
     logTxt("RInside::ctor BEGIN", verbose);
 
     if (instance_) {
-    	throw std::runtime_error( "can only have one RInside instance" ) ;
+        throw std::runtime_error( "can only have one RInside instance" ) ;
     } else {
-    	instance_ = this ;	
+        instance_ = this ;      
     }
     
-    verbose_m = false; 		// Default is false
+    verbose_m = false;          // Default is false
 
     // generated as littler.h via from svn/littler/littler.R
     #include <RInsideEnvVars.h>
 
     for (int i = 0; R_VARS[i] != NULL; i+= 2) {
-	if (getenv(R_VARS[i]) == NULL) { // if env variable is not yet set
-	    if (setenv(R_VARS[i],R_VARS[i+1],1) != 0){
-		//perror("ERROR: couldn't set/replace an R environment variable");
-		//exit(1);
-		throw std::runtime_error(std::string("Could not set R environment variable ") +
-					 std::string(R_VARS[i]) + std::string(" to ") +  
-					 std::string(R_VARS[i+1]));
-	    }
-	}
+        if (getenv(R_VARS[i]) == NULL) { // if env variable is not yet set
+            if (setenv(R_VARS[i],R_VARS[i+1],1) != 0){
+                //perror("ERROR: couldn't set/replace an R environment variable");
+                //exit(1);
+                throw std::runtime_error(std::string("Could not set R environment variable ") +
+                                         std::string(R_VARS[i]) + std::string(" to ") +  
+                                         std::string(R_VARS[i+1]));
+            }
+        }
     }
 
     #ifndef WIN32
-    R_SignalHandlers = 0;    		// Don't let R set up its own signal handlers
+    R_SignalHandlers = 0;               // Don't let R set up its own signal handlers
     #endif
 
     #ifdef CSTACK_DEFNS
-    R_CStackLimit = (uintptr_t)-1;	// Don't do any stack checking, see R Exts, '8.1.5 Threading issues' 
+    R_CStackLimit = (uintptr_t)-1;      // Don't do any stack checking, see R Exts, '8.1.5 Threading issues' 
     #endif
 
     init_tempdir();
@@ -108,34 +141,45 @@
     int R_argc = (sizeof(R_argv) - sizeof(R_argv_opt) ) / sizeof(R_argv[0]);
     Rf_initEmbeddedR(R_argc, (char**)R_argv);
 
-    R_ReplDLLinit(); 			// this is to populate the repl console buffers 
+    R_ReplDLLinit();                    // this is to populate the repl console buffers 
 
     structRstart Rst;
     R_DefParams(&Rst);
-    Rst.R_Interactive = (Rboolean) FALSE;	// sets interactive() to eval to false 
+    Rst.R_Interactive = (Rboolean) FALSE;       // sets interactive() to eval to false 
+    #ifdef WIN32
+    Rst.rhome = getenv("R_HOME");       // which is set above as part of R_VARS 
+    Rst.home = getRUser();
+    Rst.CharacterMode = LinkDLL;
+    Rst.ReadConsole = myReadConsole;
+    Rst.WriteConsole = myWriteConsole;
+    Rst.CallBack = myCallBack;
+    Rst.ShowMessage = myAskOk;
+    Rst.YesNoCancel = myAskYesNoCancel;
+    Rst.Busy = myBusy;
+    #endif
     R_SetParams(&Rst);
 
     global_env = R_GlobalEnv ;
     
-    if (loadRcpp) {			// if asked for, load Rcpp (before the autoloads)
-	// Rf_install is used best by first assigning like this so that symbols get into the symbol table 
-	// where they cannot be garbage collected; doing it on the fly does expose a minuscule risk of garbage  
-	// collection -- with thanks to Doug Bates for the explanation and Luke Tierney for the heads-up
-	SEXP suppressMessagesSymbol = Rf_install("suppressMessages");
-	SEXP requireSymbol = Rf_install("require");
-	Rf_eval(Rf_lang2(suppressMessagesSymbol, Rf_lang2(requireSymbol, Rf_mkString("Rcpp"))), R_GlobalEnv);
+    if (loadRcpp) {                     // if asked for, load Rcpp (before the autoloads)
+        // Rf_install is used best by first assigning like this so that symbols get into the symbol table 
+        // where they cannot be garbage collected; doing it on the fly does expose a minuscule risk of garbage  
+        // collection -- with thanks to Doug Bates for the explanation and Luke Tierney for the heads-up
+        SEXP suppressMessagesSymbol = Rf_install("suppressMessages");
+        SEXP requireSymbol = Rf_install("require");
+        Rf_eval(Rf_lang2(suppressMessagesSymbol, Rf_lang2(requireSymbol, Rf_mkString("Rcpp"))), R_GlobalEnv);
     }
 
-    autoloads();    			// loads all default packages
+    autoloads();                        // loads all default packages
 
-    if ((argc - optind) > 1){    	// for argv vector in Global Env */
-	Rcpp::CharacterVector s_argv( argv+(1+optind), argv+argc );
-	assign(s_argv, "argv");
+    if ((argc - optind) > 1){           // for argv vector in Global Env */
+        Rcpp::CharacterVector s_argv( argv+(1+optind), argv+argc );
+        assign(s_argv, "argv");
     } else {
-	assign(R_NilValue, "argv") ;
+        assign(R_NilValue, "argv") ;
     }
   
-    init_rand();    			// for tempfile() to work correctly */
+    init_rand();                        // for tempfile() to work correctly */
     logTxt("RInside::ctor END", verbose);
 }
 
@@ -144,22 +188,22 @@
     // FIXME:  if per-session temp directory is used (as R does) then return
     tmp = getenv("TMPDIR");
     if (tmp == NULL) {
-	tmp = getenv("TMP");
-	if (tmp == NULL) { 
-	    tmp = getenv("TEMP");
-	    if (tmp == NULL) 
-		tmp = "/tmp";
-	    }
+        tmp = getenv("TMP");
+        if (tmp == NULL) { 
+            tmp = getenv("TEMP");
+            if (tmp == NULL) 
+                tmp = "/tmp";
+            }
     }
     R_TempDir = (char*) tmp;
     if (setenv("R_SESSION_TMPDIR",tmp,1) != 0){
-	//perror("Fatal Error: couldn't set/replace R_SESSION_TMPDIR!");
-	//exit(1);
-	throw std::runtime_error(std::string("Could not set / replace R_SESSION_TMPDIR to ") + std::string(tmp));
+        //perror("Fatal Error: couldn't set/replace R_SESSION_TMPDIR!");
+        //exit(1);
+        throw std::runtime_error(std::string("Could not set / replace R_SESSION_TMPDIR to ") + std::string(tmp));
     }
 }
 
-void RInside::init_rand(void) {	/* set seed for tempfile()  */
+void RInside::init_rand(void) { /* set seed for tempfile()  */
     unsigned int seed;
     struct timeval tv;
     gettimeofday (&tv, NULL);
@@ -201,10 +245,10 @@
     // we build the call : 
     //
     //  delayedAssign( NAME, 
-    //  	autoloader( name = NAME, package = PACKAGE), 
-    //  	.GlobalEnv, 
-    //  	.AutoloadEnv )
-    //  	
+    //          autoloader( name = NAME, package = PACKAGE), 
+    //          .GlobalEnv, 
+    //          .AutoloadEnv )
+    //          
     //  where : 
     //  - PACKAGE is updated in a loop
     //  - NAME is updated in a loop
@@ -213,46 +257,46 @@
      
     int i,j, idx=0, nobj ;
     Rcpp::Language delayed_assign_call(Rcpp::Function("delayedAssign"), 
-				       R_NilValue,     // arg1: assigned in loop 
-				       R_NilValue,     // arg2: assigned in loop 
-				       global_env,
-				       global_env.find(".AutoloadEnv")
-				       ) ;
+                                       R_NilValue,     // arg1: assigned in loop 
+                                       R_NilValue,     // arg2: assigned in loop 
+                                       global_env,
+                                       global_env.find(".AutoloadEnv")
+                                       );
     Rcpp::Language::Proxy delayed_assign_name  = delayed_assign_call[1];
 
     Rcpp::Language autoloader_call(Rcpp::Function("autoloader"),
-				   Rcpp::Named( "name", R_NilValue) ,  // arg1 : assigned in loop 
-				   Rcpp::Named( "package", R_NilValue) // arg2 : assigned in loop 
-				   );
+                                   Rcpp::Named( "name", R_NilValue) ,  // arg1 : assigned in loop 
+                                   Rcpp::Named( "package", R_NilValue) // arg2 : assigned in loop 
+                                   );
     Rcpp::Language::Proxy autoloader_name = autoloader_call[1];
     Rcpp::Language::Proxy autoloader_pack = autoloader_call[2];
-    delayed_assign_call[2] = autoloader_call ;
+    delayed_assign_call[2] = autoloader_call;
     
     try { 
-    	for( i=0; i<packc; i++){
-    		
-	    // set the 'package' argument of the autoloader call */
-	    autoloader_pack = pack[i] ;
-		
-	    nobj = packobjc[i] ; 
-	    for (j = 0; j < nobj ; j++){
-		
-		// set the 'name' argument of the autoloader call */ 
-		autoloader_name = packobj[idx+j] ;
-		   
-		// Set the 'name' argument of the delayedAssign call */
-		delayed_assign_name = packobj[idx+j] ;
-		    
-		// evaluate the call */
-		delayed_assign_call.eval() ;
-		    
-	    }
-	    idx += packobjc[i] ;
-    	}
+        for( i=0; i<packc; i++){
+                
+            // set the 'package' argument of the autoloader call */
+            autoloader_pack = pack[i] ;
+                
+            nobj = packobjc[i] ; 
+            for (j = 0; j < nobj ; j++){
+                
+                // set the 'name' argument of the autoloader call */ 
+                autoloader_name = packobj[idx+j] ;
+                   
+                // Set the 'name' argument of the delayedAssign call */
+                delayed_assign_name = packobj[idx+j] ;
+                    
+                // evaluate the call */
+                delayed_assign_call.eval() ;
+                    
+            }
+            idx += packobjc[i] ;
+        }
     } catch( std::exception& ex){
-	// fprintf(stderr,"%s: Error calling delayedAssign:\n %s", programName, ex.what() );
-	// exit(1);	    
-	throw std::runtime_error(std::string("Error calling delayedAssign: ") + std::string(ex.what()));
+        // fprintf(stderr,"%s: Error calling delayedAssign:\n %s", programName, ex.what() );
+        // exit(1);         
+        throw std::runtime_error(std::string("Error calling delayedAssign: ") + std::string(ex.what()));
     }
 }
 
@@ -271,41 +315,41 @@
 
     switch (status){
     case PARSE_OK:
-	// Loop is needed here as EXPSEXP might be of length > 1 
-	for(i = 0; i < Rf_length(cmdexpr); i++){
-	    ans = R_tryEval(VECTOR_ELT(cmdexpr, i),NULL,&errorOccurred);
-	    if (errorOccurred) {
-		fprintf(stderr, "%s: Error in evaluating R code (%d)\n", programName, status);
-		UNPROTECT(2);
-		return 1;
-	    }
-	    if (verbose_m) {
-		Rf_PrintValue(ans);
-	    }
-	}
-	mb_m.rewind();
-	break;
+        // Loop is needed here as EXPSEXP might be of length > 1 
+        for(i = 0; i < Rf_length(cmdexpr); i++){
+            ans = R_tryEval(VECTOR_ELT(cmdexpr, i),NULL,&errorOccurred);
+            if (errorOccurred) {
+                fprintf(stderr, "%s: Error in evaluating R code (%d)\n", programName, status);
+                UNPROTECT(2);
+                return 1;
+            }
+            if (verbose_m) {
+                Rf_PrintValue(ans);
+            }
+        }
+        mb_m.rewind();
+        break;
     case PARSE_INCOMPLETE:
-	// need to read another line 
-	break;
+        // need to read another line 
+        break;
     case PARSE_NULL:
-	fprintf(stderr, "%s: ParseStatus is null (%d)\n", programName, status);
-	UNPROTECT(2);
-	return 1;
-	break;
+        fprintf(stderr, "%s: ParseStatus is null (%d)\n", programName, status);
+        UNPROTECT(2);
+        return 1;
+        break;
     case PARSE_ERROR:
-	fprintf(stderr,"Parse Error: \"%s\"\n", line.c_str());
-	UNPROTECT(2);
-	return 1;
-	break;
+        fprintf(stderr,"Parse Error: \"%s\"\n", line.c_str());
+        UNPROTECT(2);
+        return 1;
+        break;
     case PARSE_EOF:
-	fprintf(stderr, "%s: ParseStatus is eof (%d)\n", programName, status);
-	break;
+        fprintf(stderr, "%s: ParseStatus is eof (%d)\n", programName, status);
+        break;
     default:
-	fprintf(stderr, "%s: ParseStatus is not documented %d\n", programName, status);
-	UNPROTECT(2);
-	return 1;
-	break;
+        fprintf(stderr, "%s: ParseStatus is not documented %d\n", programName, status);
+        UNPROTECT(2);
+        return 1;
+        break;
     }
     UNPROTECT(2);
     return 0;
@@ -315,7 +359,7 @@
     SEXP ans;
     int rc = parseEval(line, ans);
     if (rc != 0) {
-	throw std::runtime_error(std::string("Error evaluating: ") + line);
+        throw std::runtime_error(std::string("Error evaluating: ") + line);
     }
 }
 
@@ -323,7 +367,7 @@
     SEXP ans;
     int rc = parseEval(line, ans);
     if (rc != 0) {
-	throw std::runtime_error(std::string("Error evaluating: ") + line);
+        throw std::runtime_error(std::string("Error evaluating: ") + line);
     }
     return Proxy( ans );
 }
@@ -333,7 +377,7 @@
 }
 
 RInside& RInside::instance(){
-	return *instance_ ;
+    return *instance_ ;
 }
 
 /* callbacks */
@@ -342,40 +386,40 @@
 
 void Callbacks::Busy_( int which ){
     R_is_busy = static_cast<bool>( which ) ;
-    Busy( R_is_busy ) ;	
+    Busy( R_is_busy ) ; 
 }
 
 int Callbacks::ReadConsole_( const char* prompt, unsigned char* buf, int len, int addtohistory ){
     try {
-	std::string res( ReadConsole( prompt, static_cast<bool>(addtohistory) ) ) ;
-		
-	/* At some point we need to figure out what to do if the result is
-	 * longer than "len"... For now, just truncate. */
-		 
-	int l = res.size() ;
-	int last = (l>len-1)?len-1:l ;
-	strncpy( (char*)buf, res.c_str(), last ) ;
-	buf[last] = 0 ;
-	return 1 ;
+        std::string res( ReadConsole( prompt, static_cast<bool>(addtohistory) ) ) ;
+                
+        /* At some point we need to figure out what to do if the result is
+         * longer than "len"... For now, just truncate. */
+                 
+        int l = res.size() ;
+        int last = (l>len-1)?len-1:l ;
+        strncpy( (char*)buf, res.c_str(), last ) ;
+        buf[last] = 0 ;
+        return 1 ;
     } catch( const std::exception& ex){
-	return -1 ;	
+        return -1 ;     
     }
 }
 
 
 void Callbacks::WriteConsole_( const char* buf, int len, int oType ){
     if( len ){
-	buffer.assign( buf, buf + len - 1 ) ;
-	WriteConsole( buffer, oType) ;
+        buffer.assign( buf, buf + len - 1 ) ;
+        WriteConsole( buffer, oType) ;
     }
 }
 
 void RInside_ShowMessage( const char* message ){
-    RInside::instance().callbacks->ShowMessage( message ) ;	
+    RInside::instance().callbacks->ShowMessage( message ) ;     
 }
 
 void RInside_WriteConsoleEx( const char* message, int len, int oType ){
-    RInside::instance().callbacks->WriteConsole_( message, len, oType ) ;		
+    RInside::instance().callbacks->WriteConsole_( message, len, oType ) ;               
 }
 
 int RInside_ReadConsole(const char *prompt, unsigned char *buf, int len, int addtohistory){
@@ -400,33 +444,33 @@
 
 void RInside::set_callbacks(Callbacks* callbacks_){
     callbacks = callbacks_ ;
-	
+        
 #ifdef WIN32
     // do something to tell user that he doesn't get this
 #else
 
     /* short circuit the callback function pointers */
     if( callbacks->has_ShowMessage() ){
-	ptr_R_ShowMessage = RInside_ShowMessage ;
+        ptr_R_ShowMessage = RInside_ShowMessage ;
     }
     if( callbacks->has_ReadConsole() ){
-	ptr_R_ReadConsole = RInside_ReadConsole;
+        ptr_R_ReadConsole = RInside_ReadConsole;
     }
     if( callbacks->has_WriteConsole() ){
-    	ptr_R_WriteConsoleEx = RInside_WriteConsoleEx ;
-    	ptr_R_WriteConsole = NULL;
-	}
+        ptr_R_WriteConsoleEx = RInside_WriteConsoleEx ;
+        ptr_R_WriteConsole = NULL;
+        }
     if( callbacks->has_ResetConsole() ){
-	ptr_R_ResetConsole = RInside_ResetConsole;
+        ptr_R_ResetConsole = RInside_ResetConsole;
     }
     if( callbacks->has_FlushConsole() ){
-    	ptr_R_FlushConsole = RInside_FlushConsole;
+        ptr_R_FlushConsole = RInside_FlushConsole;
     }
     if( callbacks->has_CleanerrConsole() ){
-    	ptr_R_ClearerrConsole = RInside_ClearerrConsole;
+        ptr_R_ClearerrConsole = RInside_ClearerrConsole;
     }
     if( callbacks->has_Busy() ){
-    	ptr_R_Busy = RInside_Busy;
+        ptr_R_Busy = RInside_Busy;
     }
     
     R_Outputfile = NULL;



More information about the Rinside-commits mailing list