[Opensrf-commits] r1848 - trunk/src/srfsh (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Nov 10 17:50:21 EST 2009


Author: scottmk
Date: 2009-11-10 17:50:14 -0500 (Tue, 10 Nov 2009)
New Revision: 1848

Modified:
   trunk/src/srfsh/srfsh.c
Log:
1. Fixed a bug whereby the display of request results was not showing up
when pretty-printing was turned off.  We were calling jsonObjectGetString()
when we should have been calling jsonObjectToJSON(), and thereby getting
NULL instead of a usable string, for any but the most trivial of results.

Also: applied some minor refinements to nearby code.

2. In handle_request(): eliminated a couple of superfluous variables.

3. Corrected an erroneous statement in the help message.  Request output
passes through less when raw_print is false, not when it's true.

4. Tidied up the white space here and there.

M    src/srfsh/srfsh.c


Modified: trunk/src/srfsh/srfsh.c
===================================================================
--- trunk/src/srfsh/srfsh.c	2009-11-09 04:22:35 UTC (rev 1847)
+++ trunk/src/srfsh/srfsh.c	2009-11-10 22:50:14 UTC (rev 1848)
@@ -703,12 +703,10 @@
 	if(!client)
 		return 1;
 
-	const char* word_1 = osrfStringArrayGetString( cmd_array, 1 );
-	const char* word_2 = osrfStringArrayGetString( cmd_array, 2 );
+	const char* server = osrfStringArrayGetString( cmd_array, 1 );
+	const char* method = osrfStringArrayGetString( cmd_array, 2 );
 
-	if( word_1 ) {
-		const char* server = word_1;
-		const char* method = word_2;
+	if( server ) {
 		int i;
 		growing_buffer* buffer = NULL;
 		if( !relay ) {
@@ -823,17 +821,18 @@
 	
 				if( pretty_print ) {
 					char* j = jsonObjectToJSON(omsg->_result_content);
-					//content = json_printer(j); 
-					content = jsonFormatString(j);
-					free(j);
+					if( j ) {
+						content = jsonFormatString(j);
+						free(j);
+					} else
+						content = strdup( "(null)" );
 				} else {
-					const char * temp_content = jsonObjectGetString(omsg->_result_content);
-					if( ! temp_content )
-						temp_content = "[null]";
-					content = strdup( temp_content );
+					content = jsonObjectToJSON(omsg->_result_content);
+					if( ! content )
+						content = strdup( "(null)" );
 				}
-				
-				printf( "\nReceived Data: %s\n", content ); 
+
+				printf( "\nReceived Data: %s\n", content );
 				free(content);
 	
 			} else {
@@ -860,24 +859,24 @@
 	
 				if( pretty_print && omsg->_result_content ) {
 					char* j = jsonObjectToJSON(omsg->_result_content);
-					//content = json_printer(j); 
-					content = jsonFormatString(j);
-					free(j);
+					if( j ) {
+						content = jsonFormatString(j);
+						free(j);
+					} else
+						content = strdup( "(null)" );
 				} else {
-					const char * temp_content = jsonObjectGetString(omsg->_result_content);
-					if( temp_content )
-						content = strdup( temp_content );
-					else
-						content = NULL;
+					content = jsonObjectToJSON(omsg->_result_content);
+					if( ! content )
+						content = strdup( "(null)" );
 				}
 
-				buffer_add( resp_buffer, "\nReceived Data: " ); 
+				buffer_add( resp_buffer, "\nReceived Data: " );
 				buffer_add( resp_buffer, content );
-				buffer_add( resp_buffer, "\n" );
+				buffer_add_char( resp_buffer, '\n' );
 				free(content);
-	
+
 			} else {
-	
+
 				buffer_add( resp_buffer, "\nReceived Exception:\nName: " );
 				buffer_add( resp_buffer, omsg->status_name );
 				buffer_add( resp_buffer, "\nStatus: " );
@@ -906,7 +905,7 @@
 	fprintf(less, "Request Time in seconds: %.6f\n", end - start );
 	fputs("------------------------------------\n", less);
 
-	pclose(less); 
+	pclose(less);
 
 	osrf_app_session_request_finish( session, req_id );
 
@@ -1026,8 +1025,8 @@
 			"       - To view the session id later, enter: print login\n"
 			"---------------------------------------------------------------------------------\n"
 			"\n"
-			"Note: long output is piped through 'less' when the 'raw_print' variable is true.\n"
-			"To search in 'less', type: /<search>\n"
+			"Note: long output is piped through 'less' unless the 'raw_print' variable\n"
+			"is true.  To search in 'less', type: /<search>\n"
 			"---------------------------------------------------------------------------------\n"
 			"\n",
 			stdout );



More information about the opensrf-commits mailing list