--- utils/rpctrace.c	2005-07-08 10:14:55.000000000 -0500
+++ utils/rpctraceNEW.c	2005-07-05 22:44:26.000000000 -0500
@@ -33,6 +33,7 @@
 #include <sys/wait.h>
 #include <inttypes.h>
 #include <stddef.h>
+#include <ctype.h>
 
 const char *argp_program_version = STANDARD_HURD_VERSION (rpctrace);
 
@@ -541,7 +542,7 @@
 		  /* XXX
 		   */
 		  fprintf (ostream,
-			   "\t\t[%d] = pass through port %d, type %d\n",
+			   "[%d] = pass through port %d, type %d",
 			   i, portnames[i], name);
 		  continue;
 		}
@@ -833,14 +834,14 @@
   expected_reply_port = msg->msgh_local_port;
 
   if (receiver->name != 0)
-    fprintf (ostream, "%4s->", receiver->name);
-  else
-    fprintf (ostream, "%4u->", (unsigned int) receiver->pi.port_right);
-
+    fprintf (ostream, "%4s[", receiver->name); 
+  else 
+    fprintf (ostream, "Request Port Right(%4u  ) \n\trequest[", (unsigned int) receiver->pi.port_right); 
+  
   if (msgname != 0)
-    fprintf (ostream, "%5s (", msgname);
-  else
-    fprintf (ostream, "%5u (", (unsigned int) msg->msgh_id);
+    fprintf (ostream, "%5s (", msgname); 
+  else 
+    fprintf (ostream, "%5u (", (unsigned int) msg->msgh_id); 
 }
 
 static void
@@ -861,7 +862,7 @@
       /* We have printed a partial line for the request message,
 	 and now we have the corresponding reply.  */
       if (reply->Head.msgh_id == info->u.send_once.sent_msgid + 100)
-	fprintf (ostream, " = "); /* normal case */
+	fprintf (ostream, " \n\treply "); /* normal case */
       else
 	/* This is not the proper reply message ID.  */
 	fprintf (ostream, " =(%u != %u) ",
@@ -910,6 +911,35 @@
   expected_reply_port = MACH_PORT_NULL;
 }
 
+/*
+ * This should clean the output up a little making things look just that
+ * much nicer.
+ */
+int stripSpaces (char *old, char *new) {
+  int space = 0;
+  int n = 0;
+  int i = 0;
+
+  for (i = 0; old[i] != '\0'; i++) {
+    if (!isalpha (old[i])   && 
+	!isalnum (old[i])   && 
+	!ispunct (old[i])   &&
+	space == 0) {
+      new[n] = ' ';
+      space = 1;
+      ++n;
+    }
+    
+    if (isalpha (old[i]) ||
+	isalnum (old[i]) || 
+	ispunct (old[i])) {
+      new[n] = old[i];
+      space = 0;
+      ++n;
+    }
+  }
+  return 0;
+}
 
 static void
 print_data (mach_msg_type_name_t type,
@@ -923,7 +953,7 @@
       assert (eltsize == sizeof (mach_port_t));
       {
 	mach_msg_type_number_t i;
-	fprintf (ostream, "pn{");
+	fprintf (ostream, "port name{");
 	for (i = 0; i < nelt; ++i)
 	  {
 	    fprintf (ostream, "%*u", (i > 0) ? 4 : 3,
@@ -935,9 +965,20 @@
 
     case MACH_MSG_TYPE_STRING:
     case MACH_MSG_TYPE_CHAR:
-      fprintf (ostream, "\"%.*s\"",
-	       (int) (nelt * eltsize), (const char *) data);
-      return;
+      {
+	int dataLen = strlen ((const char *)data);
+	char *strippedData = (char *)malloc (dataLen + 1);
+	/*
+	 * Strip out all the spaces, and insert just one space
+	 * inbetween each data element.  This should make the
+	 * output look a little bit cleaner and not so spaced
+	 * out.
+	 */
+	stripSpaces ((const char *)data, strippedData);
+	fprintf (ostream, "\"%.*s\"",
+		 (int) (nelt * eltsize), (const char *) strippedData);
+	return;
+      }
 
 #if 0
     case MACH_MSG_TYPE_CHAR:
@@ -950,8 +991,8 @@
 	mach_msg_type_number_t i;					      \
 	for (i = 0; i < nelt; ++i)					      \
 	  {								      \
-	    fprintf (ostream, "%s" fmt,					      \
-		     (i == 0 && nelt > 1) ? "{" : i > 0 ? " " : "",	      \
+	    fprintf (ostream, "%s" fmt,		        		      \
+		     (i == 0 && nelt > 1) ? "\n\tDATA{" : i > 0 ? ((i % 12) == 0) ? "\n\t" : " " : "",   \
 		     *(const ctype *) data);				      \
 	    data += eltsize;						      \
 	  }								      \
@@ -1026,9 +1067,11 @@
   if (pid < 0)
     error (2, errno, "task2pid");
 
+  /* Print the header. */
+  fprintf (ostream, "Tracing all RPC request and replies for task %s with pid %d\n\n", argv[0], (int) pid);
+    
   /* Create a trace wrapper for the task port.  */
   ti = new_send_wrapper (traced_task, &task_wrapper);/* consumes ref */
-  asprintf (&ti->name, "task%d", (int) pid);
 
   /* Replace the task's kernel port with the wrapper.  When this task calls
      `mach_task_self ()', it will get our wrapper send right instead of its
@@ -1059,7 +1102,6 @@
 {
   const char *outfile = 0;
   char **cmd_argv = 0;
-  error_t err;
 
   /* Parse our options...  */
   error_t parse_opt (int key, char *arg, struct argp_state *state)
@@ -1119,16 +1161,17 @@
   {
     pid_t child, pid;
     int status;
+
     child = traced_spawn (cmd_argv, envp);
     pid = waitpid (child, &status, 0);
     sleep (1);			/* XXX gives other thread time to print */
     if (pid != child)
       error (1, errno, "waitpid");
     if (WIFEXITED (status))
-      fprintf (ostream, "Child %d exited with %d\n",
+      fprintf (ostream, "\nProcess %d exited with %d\n",
 	       pid, WEXITSTATUS (status));
     else
-      fprintf (ostream, "Child %d %s\n", pid, strsignal (WTERMSIG (status)));
+      fprintf (ostream, "\nProcess %d %s\n", pid, strsignal (WTERMSIG (status)));
   }
 
   return 0;
