2 dstream.cc -- implement Dstream
4 source file of the Flower Library
6 (c) 1996, 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "dictionary-iter.hh"
11 #include "dictionary.hh"
13 #include "string-convert.hh"
14 #include "rational.hh"
16 /// amount of indentation for each level.
20 should use Regexp library.
23 strip_pretty (String pretty_str)
25 int i = pretty_str.index_i ('(');
27 pretty_str = pretty_str.left_str (i);
29 int l = pretty_str.index_last_i (' '); // strip until last ' '
31 pretty_str = pretty_str.nomid_str (0,l+1);
36 strip_member (String pret)
38 int l=pret.index_last_i (':')-1;
40 pret = pret.left_str (l);
45 Dstream::identify_as (String name)
50 String mem (strip_pretty (name));
51 String cl (strip_member (mem));
54 if (silent_dict_p_->elem_b (mem))
56 else if (silent_dict_p_->elem_b (cl))
60 (*silent_dict_p_)[idx] = default_silence_b_;
62 local_silence_b_ = (*silent_dict_p_)[idx];
63 if (current_classname_str_ != idx && !local_silence_b_)
65 current_classname_str_=idx;
66 if (! (*silent_dict_p_)["Dstream"])
67 *os_l_ << "[" << current_classname_str_ << ":]"; // messy.
73 Dstream::silent_b (String s) const
78 if (!silent_dict_p_->elem_b (s))
80 return (*silent_dict_p_)[s];
84 Dstream::operator<< (void const *v_l)
86 output (String_convert::pointer_str (v_l));
91 Dstream::operator << (String s)
98 Dstream::operator << (const char * s)
105 Dstream::operator << (char c)
112 Dstream::operator << (Real r)
118 Dstream::operator << (Rational c)
124 Dstream::operator << (int i)
131 Dstream::output (String s)
133 if (local_silence_b_|| !os_l_)
136 for (char const *cp = s.ch_C (); *cp; cp++)
141 case '(': indent_level_i_ += INDTAB;
148 indent_level_i_ -= INDTAB;
151 assert (indent_level_i_>=0) ;
155 *os_l_ << '\n' << to_str (' ', indent_level_i_) << flush;
165 Dstream::Dstream (ostream *r, char const * cfg_nm)
168 silent_dict_p_ = new Dictionary<bool>;
169 default_silence_b_ = false;
174 char const * fn =cfg_nm ? cfg_nm : ".dstreamrc";
176 ifstream ifs (fn); // can 't open
182 while (!cfg.eof_b ()){
183 Text_record r (cfg++);
186 r.message (_ ("not enough fields in Dstream init"));
189 (*silent_dict_p_)[r[0]] = r[1] == "1";
192 if ((*silent_dict_p_).elem_b ("Dstream_default_silence"))
193 default_silence_b_ = (*silent_dict_p_)["Dstream_default_silence"];
199 delete silent_dict_p_;
200 assert (!indent_level_i_) ;
204 Dstream::clear_silence ()
206 delete silent_dict_p_;