[rkward-cvs] rkward/rkward/rbackend rcommand.h,1.9,1.10 rembed.cpp,1.13,1.14 rembedinternal.cpp,1.10,1.11 rembedinternal.h,1.4,1.5

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Apr 15 13:23:15 UTC 2005


Update of /cvsroot/rkward/rkward/rkward/rbackend
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22288/rbackend

Modified Files:
	rcommand.h rembed.cpp rembedinternal.cpp rembedinternal.h 
Log Message:
Store information on type of error in RCommand. Will allow detecting incomplete statements in RKConsole

Index: rcommand.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rcommand.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** rcommand.h	9 Sep 2004 15:13:13 -0000	1.9
--- rcommand.h	15 Apr 2005 13:23:13 -0000	1.10
***************
*** 108,112 ****
  	although partially exclusive. */
  	enum CommandTypes {User=1, Plugin=2, PluginCom=4, App=8, Sync=16, EmptyCommand=32, GetIntVector=512, GetStringVector=1024, GetRealVector=2048, DirectToOutput=4096, Canceled=8192 };
! 	enum CommandStatus {WasTried=1, Failed=2, HasOutput=4, HasError=8};
  	bool wasTried () { return (status & WasTried); };
  	bool failed () { return (status & Failed); };
--- 108,112 ----
  	although partially exclusive. */
  	enum CommandTypes {User=1, Plugin=2, PluginCom=4, App=8, Sync=16, EmptyCommand=32, GetIntVector=512, GetStringVector=1024, GetRealVector=2048, DirectToOutput=4096, Canceled=8192 };
! 	enum CommandStatus {WasTried=1, Failed=2, HasOutput=4, HasError=8, ErrorIncomplete=512, ErrorSyntax=1024, ErrorOther=2048};
  	bool wasTried () { return (status & WasTried); };
  	bool failed () { return (status & Failed); };
***************
*** 114,117 ****
--- 114,119 ----
  	bool hasOutput () { return (status & HasOutput); };
  	bool hasError () { return (status & HasError); };
+ 	bool errorIncomplete () { return (status & ErrorIncomplete); };
+ 	bool errorSyntax () { return (status & ErrorSyntax); };
  	int stringVectorLength () { return (string_count); };
  	int realVectorLength () { return (real_count); };

Index: rembedinternal.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rembedinternal.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** rembedinternal.h	7 Sep 2004 13:45:24 -0000	1.4
--- rembedinternal.h	15 Apr 2005 13:23:13 -0000	1.5
***************
*** 29,40 ****
  	REmbedInternal();
  	virtual ~REmbedInternal();
  protected:
  	bool startR (const char* r_home, int argc, char **argv);
  	void shutdown ();
! 	void runCommandInternal (const char *command, bool *error, bool print_result=false);
  	
! 	char **getCommandAsStringVector (const char *command, int *count, bool *error);
! 	double *getCommandAsRealVector (const char *command, int *count, bool *error);
! 	int *getCommandAsIntVector (const char *command, int *count, bool *error);
  
  public:
--- 29,42 ----
  	REmbedInternal();
  	virtual ~REmbedInternal();
+ 	
+ 	enum RKWardRError { NoError=0, Incomplete=1, SyntaxError=2, OtherError=3 };
  protected:
  	bool startR (const char* r_home, int argc, char **argv);
  	void shutdown ();
! 	void runCommandInternal (const char *command, RKWardRError *error, bool print_result=false);
  	
! 	char **getCommandAsStringVector (const char *command, int *count, RKWardRError *error);
! 	double *getCommandAsRealVector (const char *command, int *count, RKWardRError *error);
! 	int *getCommandAsIntVector (const char *command, int *count, RKWardRError *error);
  
  public:

Index: rembedinternal.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rembedinternal.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** rembedinternal.cpp	15 Apr 2005 09:57:02 -0000	1.10
--- rembedinternal.cpp	15 Apr 2005 13:23:13 -0000	1.11
***************
*** 110,114 ****
  }
  
! SEXP runCommandInternalBase (const char *command, bool *error) {
  // heavy copying from RServe below
  	extern SEXP R_ParseVector(SEXP, int, int*);
--- 110,114 ----
  }
  
! SEXP runCommandInternalBase (const char *command, REmbedInternal::RKWardRError *error) {
  // heavy copying from RServe below
  	extern SEXP R_ParseVector(SEXP, int, int*);
***************
*** 116,121 ****
  	int maxParts=1;
  	int r_error = 0;
! 	int stat;
! 	int *status = &stat;
  	const char *c = command;
  	SEXP cv, pr, exp;
--- 116,121 ----
  	int maxParts=1;
  	int r_error = 0;
! 	int status;
! 	int *stat = &status;
  	const char *c = command;
  	SEXP cv, pr, exp;
***************
*** 130,136 ****
  
  	while (maxParts>0) {
! 		pr=R_ParseVector(cv, maxParts, status);
  		// 2=incomplete; 4=eof
! 		if (*status!=2 && *status!=4) {
  			break;
  		}
--- 130,136 ----
  
  	while (maxParts>0) {
! 		pr=R_ParseVector(cv, maxParts, stat);
  		// 2=incomplete; 4=eof
! 		if (status!=2 && status!=4) {
  			break;
  		}
***************
*** 139,143 ****
  	UNPROTECT(1);
  
! 	if (*status == 1) {
  		PROTECT (pr);
  		exp=R_NilValue;
--- 139,151 ----
  	UNPROTECT(1);
  
! 	if (status != 1) {
! 		if ((status == 2) || (status == 4)) {
! 			*error = REmbedInternal::Incomplete;
! 		} else {
! 			*error = REmbedInternal::SyntaxError;
! 		}
! 		exp = R_NilValue;
! 	
! 	} else {			// no error during parsing, let's try to evaluate the command
  		PROTECT (pr);
  		exp=R_NilValue;
***************
*** 147,151 ****
  			while (bi<LENGTH(pr)) {
  				SEXP pxp=VECTOR_ELT(pr, bi);
- 				r_error=0;
  				exp=R_tryEval(pxp, R_GlobalEnv, &r_error);
  				bi++;
--- 155,158 ----
***************
*** 155,175 ****
  			}
  		} else {
- 			r_error=0;
  			exp=R_tryEval(pr, R_GlobalEnv, &r_error);
  		}
  
  		UNPROTECT(1); /* pr */
- 	} else {
- 		r_error = 1;
- 	}
  
! 	if (r_error) {
! 		exp = R_NilValue;
  	}
! 	*error = (r_error != 0);
  	return exp;
  }
  
! void REmbedInternal::runCommandInternal (const char *command, bool *error, bool print_result) {
  	if (!print_result) {
  		runCommandInternalBase (command, error);
--- 162,181 ----
  			}
  		} else {
  			exp=R_tryEval(pr, R_GlobalEnv, &r_error);
  		}
  
  		UNPROTECT(1); /* pr */
  
! 		if (r_error) {
! 			*error = REmbedInternal::OtherError;
! 		} else {
! 			*error = REmbedInternal::NoError;
! 		}
  	}
! 
  	return exp;
  }
  
! void REmbedInternal::runCommandInternal (const char *command, RKWardRError *error, bool print_result) {
  	if (!print_result) {
  		runCommandInternalBase (command, error);
***************
*** 181,185 ****
  		PROTECT (exp = runCommandInternalBase (command, error));
  		if (R_Visible) {
! 			if (!*error) Rf_PrintValue (exp);
  		}
  		UNPROTECT (1);
--- 187,191 ----
  		PROTECT (exp = runCommandInternalBase (command, error));
  		if (R_Visible) {
! 			if (*error == NoError) Rf_PrintValue (exp);
  		}
  		UNPROTECT (1);
***************
*** 187,191 ****
  }
  
! char **REmbedInternal::getCommandAsStringVector (const char *command, int *count, bool *error) {	
  	SEXP exp;
  	char **strings = 0;
--- 193,197 ----
  }
  
! char **REmbedInternal::getCommandAsStringVector (const char *command, int *count, RKWardRError *error) {	
  	SEXP exp;
  	char **strings = 0;
***************
*** 193,197 ****
  	PROTECT (exp = runCommandInternalBase (command, error));
  	
! 	if (!*error) {
  		strings = extractStrings (exp, count);
  	}
--- 199,203 ----
  	PROTECT (exp = runCommandInternalBase (command, error));
  	
! 	if (*error == NoError) {
  		strings = extractStrings (exp, count);
  	}
***************
*** 199,203 ****
  	UNPROTECT (1); // exp
  	
! 	if (*error) {
  		*count = 0;
  		return 0;
--- 205,209 ----
  	UNPROTECT (1); // exp
  	
! 	if (*error != NoError) {
  		*count = 0;
  		return 0;
***************
*** 206,210 ****
  }
  
! double *REmbedInternal::getCommandAsRealVector (const char *command, int *count, bool *error) {
  	SEXP exp;
  	double *reals = 0;
--- 212,216 ----
  }
  
! double *REmbedInternal::getCommandAsRealVector (const char *command, int *count, RKWardRError *error) {
  	SEXP exp;
  	double *reals = 0;
***************
*** 212,216 ****
  	PROTECT (exp = runCommandInternalBase (command, error));
  	
! 	if (!*error) {
  		SEXP realexp;
  		PROTECT (realexp = coerceVector (exp, REALSXP));
--- 218,222 ----
  	PROTECT (exp = runCommandInternalBase (command, error));
  	
! 	if (*error == NoError) {
  		SEXP realexp;
  		PROTECT (realexp = coerceVector (exp, REALSXP));
***************
*** 226,230 ****
  	UNPROTECT (1); // exp
  	
! 	if (*error) {
  		*count = 0;
  		return 0;
--- 232,236 ----
  	UNPROTECT (1); // exp
  	
! 	if (*error != NoError) {
  		*count = 0;
  		return 0;
***************
*** 233,237 ****
  }
  
! int *REmbedInternal::getCommandAsIntVector (const char *command, int *count, bool *error) {
  	SEXP exp;
  	int *integers = 0;
--- 239,243 ----
  }
  
! int *REmbedInternal::getCommandAsIntVector (const char *command, int *count, RKWardRError *error) {
  	SEXP exp;
  	int *integers = 0;
***************
*** 239,243 ****
  	PROTECT (exp = runCommandInternalBase (command, error));
  	
! 	if (!*error) {
  		SEXP intexp;
  		PROTECT (intexp = coerceVector (exp, INTSXP));
--- 245,249 ----
  	PROTECT (exp = runCommandInternalBase (command, error));
  	
! 	if (*error == NoError) {
  		SEXP intexp;
  		PROTECT (intexp = coerceVector (exp, INTSXP));
***************
*** 252,256 ****
  	UNPROTECT (1); // exp
  	
! 	if (*error) {
  		*count = 0;
  		return 0;
--- 258,262 ----
  	UNPROTECT (1); // exp
  	
! 	if (*error != NoError) {
  		*count = 0;
  		return 0;

Index: rembed.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rembed.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** rembed.cpp	17 Mar 2005 07:37:42 -0000	1.13
--- rembed.cpp	15 Apr 2005 13:23:13 -0000	1.14
***************
*** 72,76 ****
  	}
  	
! 	bool error;
  	int status = 0;
  	
--- 72,76 ----
  	}
  	
! 	RKWardRError error;
  	int status = 0;
  	
***************
*** 110,114 ****
  	if (command->status & RCommand::Canceled) return;
  	
! 	bool error;
  	
  	int ctype = command->type ();
--- 110,114 ----
  	if (command->status & RCommand::Canceled) return;
  	
! 	RKWardRError error;
  	
  	int ctype = command->type ();
***************
*** 133,139 ****
  	MUTEX_LOCK;
  	
! 	if (error) {
  		command->status |= RCommand::WasTried | RCommand::Failed;
! 		RK_DO (qDebug ("Command failed: command was: '%s'", command->command ().latin1 ()), RBACKEND, DL_WARNING);
  	} else {
  		command->status |= RCommand::WasTried;
--- 133,149 ----
  	MUTEX_LOCK;
  	
! 	if (error != NoError) {
  		command->status |= RCommand::WasTried | RCommand::Failed;
! 		if (error == Incomplete) {
! 			command->status |= RCommand::ErrorIncomplete;
! 			RK_DO (qDebug ("Command failed (incomplete)"), RBACKEND, DL_WARNING);
! 		} else if (error == SyntaxError) {
! 			command->status |= RCommand::ErrorSyntax;
! 			RK_DO (qDebug ("Command failed (syntax)"), RBACKEND, DL_WARNING);
! 		} else {
! 			command->status |= RCommand::ErrorOther;
! 			RK_DO (qDebug ("Command failed (other)"), RBACKEND, DL_WARNING);
! 		}
! 		RK_DO (qDebug ("failed command was: '%s'", command->command ().latin1 ()), RBACKEND, DL_WARNING);
  	} else {
  		command->status |= RCommand::WasTried;





More information about the rkward-tracker mailing list