diff src/tc-rep.cc @ 1199:4f1bfa351b99

[project @ 1995-03-31 22:16:54 by jwe]
author jwe
date Fri, 31 Mar 1995 22:21:38 +0000
parents b6360f2d4fa6
children 50cc3480a2db
line wrap: on
line diff
--- a/src/tc-rep.cc	Fri Mar 31 22:13:32 1995 +0000
+++ b/src/tc-rep.cc	Fri Mar 31 22:21:38 1995 +0000
@@ -29,7 +29,6 @@
 #include <string.h>
 #include <fstream.h>
 #include <iostream.h>
-#include <strstream.h>
 
 #include "mx-base.h"
 #include "Range.h"
@@ -41,10 +40,10 @@
 #include "gripes.h"
 #include "user-prefs.h"
 #include "utils.h"
-#include "pager.h"
 #include "pr-output.h"
 #include "tree-const.h"
 #include "idx-vector.h"
+#include "unwind-prot.h"
 #include "oct-map.h"
 
 #include "tc-inlines.h"
@@ -58,6 +57,9 @@
 // Multiplier for allocating new blocks.
 static const int newlist_grow_size = 128;
 
+// Indentation level for structures.
+static int structure_indent_level = 0;
+
 static int
 any_element_is_complex (const ComplexMatrix& a)
 {
@@ -1729,13 +1731,11 @@
 }
 
 void
-TC_REP::print (void)
+TC_REP::print (ostream& output_buf)
 {
   if (error_state)
     return;
 
-  ostrstream output_buf;
-
   switch (type_tag)
     {
     case scalar_constant:
@@ -1764,18 +1764,42 @@
 
     case map_constant:
       {
-	output_buf << "<structure";
-	int first = 1;
-	for (Pix p = a_map->first (); p != 0; a_map->next (p))
+// XXX FIXME XXX -- would be nice to print the output in some standard
+// order.  Maybe all substructures first, maybe alphabetize entries,
+// etc.
+	begin_unwind_frame ("TC_REP_print");
+
+	unwind_protect_int (structure_indent_level);
+	unwind_protect_int (user_pref.struct_levels_to_print);
+
+	structure_indent_level += 2;
+
+	if (user_pref.struct_levels_to_print > 0)
 	  {
-	    if (first)
+	    user_pref.struct_levels_to_print--;
+
+	    for (Pix p = a_map->first (); p != 0; a_map->next (p))
 	      {
-		output_buf << ":";
-		first = 0;
+		const char *key = a_map->key (p);
+		tree_constant val = a_map->contents (p);
+
+		output_buf.form ("%*s%s = ", structure_indent_level,
+				 "", key);
+
+		if (print_as_structure (val))
+		  output_buf << "{\n";
+		else if (! print_as_scalar (val))
+		  output_buf << "\n";
+
+		val.print (output_buf);
 	      }
-	    output_buf << " " << a_map->key (p);
+
+	    output_buf.form ("%*s%s", structure_indent_level, "", "}\n");
 	  }
-	output_buf << ">\n";
+	else
+	  output_buf << "<structure>\n";
+
+	run_unwind_frame ("TC_REP_print");
       }
       break;
 
@@ -1785,9 +1809,6 @@
       panic_impossible ();
       break;
     }
-
-  output_buf << ends;
-  maybe_page_output (output_buf);
 }
 
 void