[rkward-cvs] SF.net SVN: rkward:[3448] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Sun Feb 20 13:17:50 UTC 2011


Revision: 3448
          http://rkward.svn.sourceforge.net/rkward/?rev=3448&view=rev
Author:   tfry
Date:     2011-02-20 13:17:50 +0000 (Sun, 20 Feb 2011)

Log Message:
-----------
Fix plugin message capturing.

Modified Paths:
--------------
    trunk/rkward/rkward/core/robject.cpp
    trunk/rkward/rkward/rbackend/rkrbackend.cpp
    trunk/rkward/rkward/rbackend/rkrbackend.h
    trunk/rkward/rkward/rbackend/rkrbackendprotocol_shared.cpp
    trunk/rkward/rkward/rbackend/rkrbackendprotocol_shared.h
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
    trunk/rkward/tests/import_export_plugins/RKTestStandard.import_spss.messages.txt
    trunk/rkward/tests/import_export_plugins/RKTestStandard.import_spss.rkout

Modified: trunk/rkward/rkward/core/robject.cpp
===================================================================
--- trunk/rkward/rkward/core/robject.cpp	2011-02-20 12:23:58 UTC (rev 3447)
+++ trunk/rkward/rkward/core/robject.cpp	2011-02-20 13:17:50 UTC (rev 3448)
@@ -22,6 +22,7 @@
 #include <klocale.h>
 
 #include "../rbackend/rinterface.h"
+#include "../rbackend/rkrbackendprotocol_shared.h"
 #include "../rkglobals.h"
 #include "robjectlist.h"
 #include "rcontainerobject.h"
@@ -505,18 +506,7 @@
 
 //static
 QString RObject::rQuote (const QString &string) {
-	QString ret;
-	int s = string.size ();
-	ret.reserve (s + 2);	// typical case: Only quotes added, no escapes needed.
-	ret.append ('\"');
-	for (int i = 0; i < s; ++i) {
-		const QChar c = string[i];
-		if ((c == '\\') || (c == '\"')) ret.append ('\\');
-		ret.append (c);
-	}
-	ret.append ('\"');
-
-	return ret;
+	return (RKRSharedFunctionality::quote (string));
 }
 
 // static

Modified: trunk/rkward/rkward/rbackend/rkrbackend.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkrbackend.cpp	2011-02-20 12:23:58 UTC (rev 3447)
+++ trunk/rkward/rkward/rbackend/rkrbackend.cpp	2011-02-20 13:17:50 UTC (rev 3448)
@@ -354,6 +354,7 @@
 		}
 	}
 
+	if (RKRBackend::this_pointer->capturing_messages) RKRBackend::this_pointer->captured_messages.append (RKRBackend::this_pointer->current_locale_codec->toUnicode (buf, buflen));
 	RKRBackend::this_pointer->handleOutput (RKRBackend::this_pointer->current_locale_codec->toUnicode (buf, buflen), buflen, type == 0 ? ROutput::Output : ROutput::Warning);
 }
 
@@ -615,6 +616,7 @@
 
 	current_locale_codec = QTextCodec::codecForLocale ();
 	r_running = false;
+	capturing_messages = false;
 
 	current_command = 0;
 
@@ -1067,7 +1069,10 @@
 	// running user commands is quite different from all other commands and should have been handled by RReadConsole
 	RK_ASSERT (!(ctype & RCommand::User));
 
-	if (ctype & RCommand::DirectToOutput) runDirectCommand (".rk.capture.messages()");
+	if (ctype & RCommand::DirectToOutput) {
+		printAndClearCapturedMessages ();
+		capturing_messages = true;
+	}
 
 	if (ctype & RCommand::QuitCommand) {
 		R_dot_Last ();		// should run while communication with frontend is still possible
@@ -1099,7 +1104,7 @@
 		repl_status.eval_depth--;
 	}
 
-	if (ctype & RCommand::DirectToOutput) runDirectCommand (".rk.print.captured.messages()");
+	if (ctype & RCommand::DirectToOutput) printAndClearCapturedMessages ();
 
 	// common error/status handling
 	if (error != NoError) {
@@ -1116,7 +1121,18 @@
 	}
 }
 
+void RKRBackend::printAndClearCapturedMessages () {
+	RK_TRACE (RBACKEND);
 
+	if (!captured_messages.isEmpty ()) {
+		runDirectCommand (".rk.cat.output (\"<h2>Messages, warnings, or errors:</h2>\\n\")");
+		runDirectCommand ("rk.print.literal (" + RKRSharedFunctionality::quote (captured_messages) + ")");
+		captured_messages.clear ();
+	}
+
+	capturing_messages = false;
+}
+
 void RKRBackend::run () {
 	RK_TRACE (RBACKEND);
 	killed = NotKilled;

Modified: trunk/rkward/rkward/rbackend/rkrbackend.h
===================================================================
--- trunk/rkward/rkward/rbackend/rkrbackend.h	2011-02-20 12:23:58 UTC (rev 3447)
+++ trunk/rkward/rkward/rbackend/rkrbackend.h	2011-02-20 13:17:50 UTC (rev 3448)
@@ -2,7 +2,7 @@
                           rkrbackend  -  description
                              -------------------
     begin                : Sun Jul 25 2004
-    copyright            : (C) 2004, 2005, 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -169,6 +169,10 @@
 /** the main loop. See \ref RKRBackend for a more detailed description */
 	void run ();
 	static void scheduleInterrupt ();
+
+	bool capturing_messages;
+	QString captured_messages;
+	void printAndClearCapturedMessages ();
 protected:
 	RCommandProxy* handleRequest (RBackendRequest *request, bool mayHandleSubstack);
 private:

Modified: trunk/rkward/rkward/rbackend/rkrbackendprotocol_shared.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkrbackendprotocol_shared.cpp	2011-02-20 12:23:58 UTC (rev 3447)
+++ trunk/rkward/rkward/rbackend/rkrbackendprotocol_shared.cpp	2011-02-20 13:17:50 UTC (rev 3448)
@@ -2,7 +2,7 @@
                           rkrbackendprotocol  -  description
                              -------------------
     begin                : Thu Nov 04 2010
-    copyright            : (C) 2010 by Thomas Friedrichsmeier
+    copyright            : (C) 2010, 2011 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -146,3 +146,19 @@
 	return ret;
 }
 
+
+
+QString RKRSharedFunctionality::quote (const QString &string) {
+	QString ret;
+	int s = string.size ();
+	ret.reserve (s + 2);	// typical case: Only quotes added, no escapes needed.
+	ret.append ('\"');
+	for (int i = 0; i < s; ++i) {
+		const QChar c = string[i];
+		if ((c == '\\') || (c == '\"')) ret.append ('\\');
+		ret.append (c);
+	}
+	ret.append ('\"');
+
+	return ret;
+}

Modified: trunk/rkward/rkward/rbackend/rkrbackendprotocol_shared.h
===================================================================
--- trunk/rkward/rkward/rbackend/rkrbackendprotocol_shared.h	2011-02-20 12:23:58 UTC (rev 3447)
+++ trunk/rkward/rkward/rbackend/rkrbackendprotocol_shared.h	2011-02-20 13:17:50 UTC (rev 3448)
@@ -2,7 +2,7 @@
                           rkrbackendprotocol  -  description
                              -------------------
     begin                : Thu Nov 04 2010
-    copyright            : (C) 2010 by Thomas Friedrichsmeier
+    copyright            : (C) 2010, 2011 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -151,4 +151,8 @@
 	int out_buf_len;
 };
 
+namespace RKRSharedFunctionality {
+	QString quote (const QString &string);
+};
+
 #endif

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R	2011-02-20 12:23:58 UTC (rev 3447)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R	2011-02-20 13:17:50 UTC (rev 3448)
@@ -334,48 +334,6 @@
 	.rk.cat.output ("<hr>\n");
 }
 
-# for caputring message output while running a plugin command
-".rk.capture.messages" <- function () {
-	if (exists (".rk.capture.messages.sinknumber", envir=as.environment ("package:rkward"), inherits=FALSE)) {
-		# We don't support nesting, so purge it, first
-		.rk.print.captured.messages ()
-	}
-	if (!exists (".rk.capture.messages.sinkfile", envir=as.environment ("package:rkward"), inherits=FALSE)) {
-		sinkfile <- tempfile ("rkward_plugin_messages")
-		assign (".rk.capture.messages.sinkfile", sinkfile, envir=as.environment ("package:rkward"))
-	} else {
-		sinkfile <- get (".rk.capture.messages.sinkfile", envir=as.environment ("package:rkward"), inherits=FALSE)
-	}
-
-	sink (file (sinkfile, open="w"), type="message")
-	assign (".rk.capture.messages.sinknumber", sink.number ("message"), envir=as.environment ("package:rkward"))
-}
-
-".rk.print.captured.messages" <- function () {
-	if (!exists (".rk.capture.messages.sinknumber", envir=as.environment ("package:rkward"), inherits=FALSE)) return ()
-
-	sinkfile <- get (".rk.capture.messages.sinkfile", envir=as.environment ("package:rkward"), inherits=FALSE)
-	if (file.exists (sinkfile)) {
-		output <- readLines (sinkfile, warn=FALSE)
-		if (length (output) > 0) {
-			.rk.cat.output ("<h2>Messages, warnings, or errors:</h2>\n")
-			rk.print.literal (output)
-		}
-	}
-
-	sinknumber <- get (".rk.capture.messages.sinknumber", envir=as.environment ("package:rkward"), inherits=FALSE)
-	if (sink.number (type="message") == sinknumber) {
-		sink (type="message")	# remove it
-	} else {
-		warning ("Message sink has been added or removed since last call to .rk.capture.messages().")
-	}
-
-	con <- getConnection (sinknumber)
-	close (con)
-
-	remove (list=".rk.capture.messages.sinknumber", envir=as.environment ("package:rkward"))
-}
-
 # Start recording commands that are submitted from rkward to R.
 # filename: filename to write to (file will be truncated!).
 # include.sync.commands: Should internal synchronisation commands be included?

Modified: trunk/rkward/tests/import_export_plugins/RKTestStandard.import_spss.messages.txt
===================================================================
--- trunk/rkward/tests/import_export_plugins/RKTestStandard.import_spss.messages.txt	2011-02-20 12:23:58 UTC (rev 3447)
+++ trunk/rkward/tests/import_export_plugins/RKTestStandard.import_spss.messages.txt	2011-02-20 13:17:50 UTC (rev 3448)
@@ -1,3 +1,3 @@
 Warning message:
-In read.spss("../import_export_plugins_testfile.sav", to.data.frame = TRUE,  :
-  ../import_export_plugins_testfile.sav: position 1: Variable name character 4 is lowercase letter \xDF
+In read.spss("import_export_plugins_testfile.sav", to.data.frame = TRUE,  :
+  import_export_plugins_testfile.sav: position 1: Variable name character 4 is lowercase letter \xDF

Modified: trunk/rkward/tests/import_export_plugins/RKTestStandard.import_spss.rkout
===================================================================
--- trunk/rkward/tests/import_export_plugins/RKTestStandard.import_spss.rkout	2011-02-20 12:23:58 UTC (rev 3447)
+++ trunk/rkward/tests/import_export_plugins/RKTestStandard.import_spss.rkout	2011-02-20 13:17:50 UTC (rev 3448)
@@ -4,10 +4,6 @@
 <li>Import as: my.spss.data</li>
 </ul>
 DATE<br>
-<h2>Messages, warnings, or errors:</h2>
-<pre>Warning message:
-In read.spss("import_export_plugins_testfile.sav", to.data.frame = TRUE,  :
-  import_export_plugins_testfile.sav: position 1: Variable name character 4 is lowercase letter \xDF</pre>
 
 
 <p align= center >


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list