2 dstream.cc -- implement Dstream
4 source file of the Flower Library
6 (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
14 #include "string-convert.hh"
15 #include "assoc-iter.hh"
16 #include "rational.hh"
18 /// indent of each level
22 should use Regexp library.
25 strip_pretty (String pretty_str)
27 int i = pretty_str.index_i ('(');
29 pretty_str = pretty_str.left_str (i);
31 int l = pretty_str.index_last_i (' '); // strip until last ' '
33 pretty_str = pretty_str.nomid_str (0,l+1);
38 strip_member (String pret)
40 int l=pret.index_last_i (':')-1;
42 pret = pret.left_str (l);
47 Dstream::identify_as (String name)
52 String mem (strip_pretty (name));
53 String cl (strip_member (mem));
56 if (silent_assoc_p_->elem_b (mem))
58 else if (silent_assoc_p_->elem_b (cl))
62 (*silent_assoc_p_)[idx] = default_silence_b_;
64 local_silence_b_ = (*silent_assoc_p_)[idx];
65 if (current_classname_str_ != idx && !local_silence_b_)
67 current_classname_str_=idx;
68 if (!(*silent_assoc_p_)["Dstream"])
69 *os_l_ << "[" << current_classname_str_ << ":]"; // messy.
75 Dstream::silent_b (String s) const
77 if (!silent_assoc_p_->elem_b (s))
79 return (*silent_assoc_p_)[s];
83 Dstream::operator<<(void const *v_l)
85 output (String_convert::pointer_str (v_l));
90 Dstream::operator <<(Scalar s)
97 Dstream::operator <<(const char * s)
104 Dstream::output (String s)
106 if (local_silence_b_|| !os_l_)
109 for (char const *cp = s.ch_C (); *cp; cp++)
114 case '(': indent_level_i_ += INDTAB;
121 indent_level_i_ -= INDTAB;
124 assert (indent_level_i_>=0) ;
128 *os_l_ << '\n' << to_str (' ', indent_level_i_) << flush;
138 Dstream::Dstream (ostream *r, char const * cfg_nm)
141 silent_assoc_p_ = new Assoc<String,bool>;
142 default_silence_b_ = false;
147 char const * fn =cfg_nm ? cfg_nm : ".dstreamrc";
149 ifstream ifs (fn); // can 't open
155 while (!cfg.eof_b ()){
156 Text_record r (cfg++);
159 r.message (_ ("Not enough fields in Dstream init."));
162 (*silent_assoc_p_)[r[0]] = (bool)(int)(Scalar (r[1]));
165 if ((*silent_assoc_p_).elem_b ("Dstream_default_silence"))
166 default_silence_b_ = (*silent_assoc_p_)["Dstream_default_silence"];
172 delete silent_assoc_p_;
173 assert (!indent_level_i_) ;
177 Dstream::clear_silence()
179 for (Assoc_iter<String, bool> i (*silent_assoc_p_); i.ok(); i++)