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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Mar 7 20:06:25 UTC 2007


Revision: 1548
          http://svn.sourceforge.net/rkward/?rev=1548&view=rev
Author:   tfry
Date:     2007-03-07 12:06:25 -0800 (Wed, 07 Mar 2007)

Log Message:
-----------
Use QStrings as deep down as possible

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/rembedinternal.cpp
    trunk/rkward/rkward/rbackend/rembedinternal.h
    trunk/rkward/rkward/rbackend/rthread.cpp
    trunk/rkward/rkward/rbackend/rthread.h

Modified: trunk/rkward/rkward/rbackend/rembedinternal.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rembedinternal.cpp	2007-03-07 16:53:37 UTC (rev 1547)
+++ trunk/rkward/rkward/rbackend/rembedinternal.cpp	2007-03-07 20:06:25 UTC (rev 1548)
@@ -168,7 +168,7 @@
 	args.chars_a = &buf;
 	args.int_a = buflen;
 	REmbedInternal::this_pointer->handleStandardCallback (&args); */
-	REmbedInternal::this_pointer->handleOutput (buf, buflen);
+	REmbedInternal::this_pointer->handleOutput (QString::fromLocal8Bit (buf, buflen), buflen, true);
 }
 
 void RResetConsole () {
@@ -550,12 +550,15 @@
 	return true;
 }
 
-SEXP runCommandInternalBase (const char *command, REmbedInternal::RKWardRError *error) {
+SEXP runCommandInternalBase (const QString &command_qstring, REmbedInternal::RKWardRError *error) {
 // some copying from RServe below
 	int r_error = 0;
 	ParseStatus status = PARSE_NULL;
 	SEXP cv, pr, exp;
 
+	QCString localc = command_qstring.local8Bit ();		// needed so the string below does not go out of scope
+	const char *command = localc;
+
 	PROTECT(cv=allocVector(STRSXP, 1));
 	SET_VECTOR_ELT(cv, 0, mkChar(command));  
 
@@ -672,11 +675,11 @@
 }
 #endif
 
-void REmbedInternal::runCommandInternal (const char *command, RKWardRError *error, bool print_result) {
+void REmbedInternal::runCommandInternal (const QString &command_qstring, RKWardRError *error, bool print_result) {
 	connectCallbacks ();		// sorry, but we will not play nicely with additional frontends trying to override our callbacks. (Unless they start their own R event loop, then they should be fine)
 
 	if (!print_result) {
-		runCommandInternalBase (command, error);
+		runCommandInternalBase (command_qstring, error);
 	} else {		// run a user command
 #ifdef USE_R_REPLDLLDO1
 /* Using R_ReplDLLdo1 () is a pain, but it seems to be the only entry point for evaluating a command as if it had been entered on a plain R console (with auto-printing if not invisible, etc.). Esp. since R_Visible is no longer exported in R 2.5.0, as it seems as of today (2007-01-17).
@@ -696,7 +699,9 @@
 		R_ReplDLLinit ();		// resets the parse buffer (things might be left over from a previous incomplete parse)
 		bool prev_iteration_was_incomplete = false;
 
-		current_buffer = command;
+		QCString localc = command_qstring.local8Bit ();		// needed so the string below does not go out of scope
+		current_buffer = localc;
+
 		repldll_buffer_transfer_finished = false;
 		Rboolean ok = (Rboolean) 1;	// set to false, if there is a jump during the R_ToplevelExec (i.e.. some sort of error)
 
@@ -748,7 +753,7 @@
 	}
 }
 
-QString *REmbedInternal::getCommandAsStringVector (const char *command, uint *count, RKWardRError *error) {	
+QString *REmbedInternal::getCommandAsStringVector (const QString &command, uint *count, RKWardRError *error) {	
 	SEXP exp;
 	QString *list = 0;
 	
@@ -767,7 +772,7 @@
 	return list;
 }
 
-double *REmbedInternal::getCommandAsRealVector (const char *command, uint *count, RKWardRError *error) {
+double *REmbedInternal::getCommandAsRealVector (const QString &command, uint *count, RKWardRError *error) {
 	SEXP exp;
 	double *reals = 0;
 	
@@ -786,7 +791,7 @@
 	return reals;
 }
 
-int *REmbedInternal::getCommandAsIntVector (const char *command, uint *count, RKWardRError *error) {
+int *REmbedInternal::getCommandAsIntVector (const QString &command, uint *count, RKWardRError *error) {
 	SEXP exp;
 	int *integers = 0;
 	
@@ -805,7 +810,7 @@
 	return integers;
 }
 
-RData *REmbedInternal::getCommandAsRData (const char *command, RKWardRError *error) {
+RData *REmbedInternal::getCommandAsRData (const QString &command, RKWardRError *error) {
 	SEXP exp;
 	RData *data = 0;
 	

Modified: trunk/rkward/rkward/rbackend/rembedinternal.h
===================================================================
--- trunk/rkward/rkward/rbackend/rembedinternal.h	2007-03-07 16:53:37 UTC (rev 1547)
+++ trunk/rkward/rkward/rbackend/rembedinternal.h	2007-03-07 20:06:25 UTC (rev 1548)
@@ -49,6 +49,7 @@
 
 class QString;
 class RData;
+class QTextCodec;
 /** This function converts a list of strings to a QStringList (locale aware), and returns the pointer. Needed to keep R and Qt includes separate. The strings can be deleted afterwards. Implementation is in rthread.cpp */
 QString *stringsToStringList (char **strings, int count);
 /** Function to delete an array of Qstring. Does delete [] strings, nothing more. But can not inline this in this class due to conflicting R and Qt includes. Implementation is in rthread.cpp */
@@ -90,47 +91,47 @@
 @param stackstart Base of stack to use in the R thread */
 	bool startR (int argc, char **argv, size_t stacksize, void *stackstart);
 /** low-level running of a command.
- at param command char* of the command to be run
+ at param command command to be run
 @param error this will be set to a value in RKWardError depending on success/failure of the command
 @param print_result whether the R_Visible flag should be set. If true, R will behave mostly as if in a regular console session. Otherwise values
 will only be printed if called for expressedly with print ("...") or similar. */
-	void runCommandInternal (const char *command, RKWardRError *error, bool print_result=false);
+	void runCommandInternal (const QString &command, RKWardRError *error, bool print_result=false);
 /** basically a wrapper to runCommandInternal (). Tries to convert the result of the command to an array of char* after running the command. Since
 this will not ever be done for user commands, the R_Visible flag will never be set.
- at param command char* of the command to be run 
+ at param command command to be run 
 @param count length of list returned
 @param error this will be set to a value in RKWardError depending on success/failure of the command
 @returns an array of QString or 0 on failure
 @see RCommand::GetStringVector */
-	QString *getCommandAsStringVector (const char *command, unsigned int *count, RKWardRError *error);
+	QString *getCommandAsStringVector (const QString &command, unsigned int *count, RKWardRError *error);
 /** basically a wrapper to runCommandInternal (). Tries to convert the result of the command to an array of double after running the command. Since
 this will not ever be done for user commands, the R_Visible flag will never be set.
- at param command char* of the command to be run 
+ at param command command to be run 
 @param count length of array returned
 @param error this will be set to a value in RKWardError depending on success/failure of the command
 @returns an array of double or 0 on failure
 @see RCommand::GetRealVector */
-	double *getCommandAsRealVector (const char *command, unsigned int *count, RKWardRError *error);
+	double *getCommandAsRealVector (const QString &command, unsigned int *count, RKWardRError *error);
 /** basically a wrapper to runCommandInternal (). Tries to convert the result of the command to an array of int after running the command. Since
 this will not ever be done for user commands, the R_Visible flag will never be set.
- at param command char* of the command to be run 
+ at param command command to be run 
 @param count length of array returned
 @param error this will be set to a value in RKWardError depending on success/failure of the command
 @returns an array of int or 0 on failure
 @see RCommand::GetIntVector */
-	int *getCommandAsIntVector (const char *command, unsigned int *count, RKWardRError *error);
+	int *getCommandAsIntVector (const QString &command, unsigned int *count, RKWardRError *error);
 /** basically a wrapper to runCommandInternal (). Tries to convert the result of the command to an RData structure after running the command. Since this will not ever be done for user commands, the R_Visible flag will never be set.
- at param command char* of the command to be run 
+ at param command command to be run 
 @param error this will be set to a value in RKWardError depending on success/failure of the command
 @returns an array of int or 0 on failure
 @see RCommand::GetStructuredData */
-	RData *getCommandAsRData (const char *command, RKWardRError *error);
+	RData *getCommandAsRData (const QString &command, RKWardRError *error);
 public:
 /** call this periodically to make R's x11 windows process their events */
 	static void processX11Events ();
 
 /** This gets called on normal R output (R_WriteConsole). Used to get at output. */
-	virtual void handleOutput (char *buf, int buf_length) = 0;
+	virtual void handleOutput (const QString &output, int len, bool regular) = 0;
 
 /** This gets called, when the console is flushed */
 	virtual void flushOutput () = 0;
@@ -167,6 +168,7 @@
 private:
 // can't declare this as part of the class, as it would confuse REmbed
 //	SEXPREC *runCommandInternalBase (const char *command, bool *error);
+	QTextCodec *current_locale_codec;
 };
  
 #endif

Modified: trunk/rkward/rkward/rbackend/rthread.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rthread.cpp	2007-03-07 16:53:37 UTC (rev 1547)
+++ trunk/rkward/rkward/rbackend/rthread.cpp	2007-03-07 20:06:25 UTC (rev 1548)
@@ -152,10 +152,9 @@
 		RKWardRError error;
 		
 		int ctype = command->type ();
-		QCString localc = command->command ().local8Bit ();		// needed so the string below does not go out of scope
-		const char *ccommand = localc;
+		QString ccommand = command->command ();		// easier typing below
 		
-		RK_DO (qDebug ("running command: %s", ccommand), RBACKEND, DL_DEBUG);
+		RK_DO (qDebug ("running command: %s", ccommand.latin1()), RBACKEND, DL_DEBUG);
 	
 		if (command->type () & RCommand::DirectToOutput) {
 			runCommandInternal (QString ("sink (\"" + RKSettingsModuleGeneral::filesPath () + "/rk_out.html\", append=TRUE, split=TRUE)\n").local8Bit (), &error);
@@ -241,7 +240,7 @@
 	}
 }
 
-void RThread::handleOutput (char *buf, int buf_length) {
+void RThread::handleOutput (const QString &output, int buf_length, bool regular) {
 	RK_TRACE (RBACKEND);
 
 // TODO: output sometimes arrives in small chunks. Maybe it would be better to keep an internal buffer, and only append it to the output, when R_FlushConsole gets called?
@@ -250,17 +249,24 @@
 	waitIfOutputPaused ();
 
 	MUTEX_LOCK;
+	ROutput::ROutputType output_type;
+	if (regular) {
+		output_type = ROutput::Output;
+	} else {
+		output_type = ROutput::Warning;
+	}
+
 	if (current_output) {
-		if (current_output->type != ROutput::Output) {
+		if (current_output->type != output_type) {
 			flushOutput ();
 		}
 	}
 	if (!current_output) {	// not an else, might have been set to 0 in the above if
 		current_output = new ROutput;
-		current_output->type = ROutput::Output;
+		current_output->type = output_type;
 		current_output->output.reserve (MAX_BUF_LENGTH + 50);
 	}
-	current_output->output.append (QString::fromLocal8Bit (buf));
+	current_output->output.append (output);
 
 	if ((out_buf_len += buf_length) > MAX_BUF_LENGTH) {
 		RK_DO (qDebug ("Output buffer has %d characters. Forcing flush", out_buf_len), RBACKEND, DL_DEBUG);

Modified: trunk/rkward/rkward/rbackend/rthread.h
===================================================================
--- trunk/rkward/rkward/rbackend/rthread.h	2007-03-07 16:53:37 UTC (rev 1547)
+++ trunk/rkward/rkward/rbackend/rthread.h	2007-03-07 20:06:25 UTC (rev 1548)
@@ -110,7 +110,7 @@
 
 /** this function is public for technical reasons, only. Don't use except from REmbedInternal! Called from REmbedInternal when the R backend
 generates standard output. @see REmbedInternal::handleOutput () */
-	void handleOutput (char *buf, int buf_length);
+	void handleOutput (const QString &output, int buf_length, bool regular);
 
 /** Flushes current output buffer. Lock the mutex before calling this function! It is called from both threads and is not re-entrant */
 	void flushOutput ();


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