2 dstream.cc -- implement Dstream
4 source file of the Flower Library
6 (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
14 #include "string-convert.hh"
15 #include "assoc-iter.hh"
17 /// indent of each level
21 should use Regexp library.
24 strip_pretty (String pretty_str)
26 int i = pretty_str.index_i ('(');
28 pretty_str = pretty_str.left_str (i);
30 int l = pretty_str.index_last_i (' '); // strip until last ' '
32 pretty_str = pretty_str.nomid_str (0,l+1);
37 strip_member (String pret)
39 int l=pret.index_last_i (':')-1;
41 pret = pret.left_str (l);
46 Dstream::identify_as (String name)
51 String mem (strip_pretty (name));
52 String cl (strip_member (mem));
55 if (silent_assoc_p_->elt_b (mem))
57 else if (silent_assoc_p_->elt_b (cl))
60 (*silent_assoc_p_)[idx] = false;
62 local_silence_b_ = (*silent_assoc_p_)[idx];
63 if (current_classname_str_ != idx && !local_silence_b_) {
64 current_classname_str_=idx;
65 if (!(*silent_assoc_p_)["Dstream"])
66 *os_l_ << "[" << current_classname_str_ << ":]"; // messy.
72 Dstream::silence (String s)
74 if (!silent_assoc_p_->elt_b (s))
76 return (*silent_assoc_p_)[s];
80 Dstream::operator<<(String s)
87 Dstream::operator<<(void const *v_l)
89 output (String_convert::pointer_str (v_l));
94 Dstream::operator<<(char const *ch_l)
101 Dstream::output (String s)
103 if (local_silence_b_|| !os_l_)
106 for (char const *cp = s ; *cp; cp++)
110 case '(': indent_level_i_ += INDTAB;
117 indent_level_i_ -= INDTAB;
120 assert (indent_level_i_>=0) ;
124 *os_l_ << '\n' << String (' ', indent_level_i_) << flush;
134 Dstream::Dstream (ostream *r, char const * cfg_nm)
137 silent_assoc_p_ = new Assoc<String,bool>;
142 char const * fn =cfg_nm ? cfg_nm : ".dstreamrc";
144 ifstream ifs (fn); // can't open
151 Text_record r (cfg++);
153 r.message ("not enough fields in Dstream init.");
156 (*silent_assoc_p_)[r[0]] = (bool)(int)(Scalar (r[1]));
164 delete silent_assoc_p_;
165 assert (!indent_level_i_) ;
169 Dstream::clear_silence()
171 for (Assoc_iter<String, bool> i (*silent_assoc_p_); i.ok(); i++) {