4 // source file of the LilyPond music typesetter
6 // (c) 1997--1998, 1998 Jan Nieuwenhuizen <janneke@gnu.org>
11 #include "mi2mu-global.hh"
12 #include "mudela-item.hh"
13 #include "mudela-stream.hh"
14 #include "string-convert.hh"
16 extern String filename_str_g
;
18 static int const INDENT_i
= 8;
20 Mudela_stream::Mudela_stream (String filename_str
)
22 filename_str_
= filename_str
;
23 pending_indent_i_
= 0;
26 comment_mode_b_
= false;
33 Mudela_stream::~Mudela_stream()
37 warning (_f ("lily indent level: %d", indent_i_
));
41 Mudela_stream::operator << (Scalar s
)
43 static String word_sep_str
= "{} \t\n";
46 int i
= s
.index_any_i (word_sep_str
) + 1;
49 String word
= s
.left_str (i
);
50 s
= s
.cut_str (i
, s
.length_i());
51 output_wrapped (word
);
57 Mudela_stream::operator << (Mudela_item
& mudela_item_r
)
59 mudela_item_r
.output (*this);
65 Mudela_stream::handle_pending_indent()
67 *os_p_
<< String_convert::char_str ('\t', pending_indent_i_
);
68 column_i_
+= pending_indent_i_
* INDENT_i
;
69 pending_indent_i_
= 0;
73 Mudela_stream::header()
75 *os_p_
<< _ ("% Creator: ");
76 if (no_timestamps_b_g
)
77 *os_p_
<< "GNU LilyPond\n";
79 *os_p_
<< mi2mu_version_str() << '\n';
80 *os_p_
<< _ ("% Automatically generated");
81 if (no_timestamps_b_g
)
85 *os_p_
<< _ (", at ");
87 *os_p_
<< ctime (&t
) << "%\n";
89 *os_p_
<< _ ("% from input file: ");
90 // *os_p_ << midi_parser_l_g->filename_str_;
92 *os_p_
<< filename_str_g
;
95 *os_p_
<< "\\version \"1.0.14\";\n";
101 os_p_
= new ofstream (filename_str_
.ch_C ());
103 error (_f ("can't open file: `%s\'", filename_str_
));
107 Mudela_stream::output (String str
)
109 for (int i
= 0; i
< str
.length_i(); i
++)
116 handle_pending_indent();
117 if (column_i_
== indent_i_
* INDENT_i
)
127 if (pending_indent_i_
)
129 handle_pending_indent();
134 handle_pending_indent();
135 comment_mode_b_
= true;
140 handle_pending_indent();
142 column_i_
+= INDENT_i
;
146 pending_indent_i_
= indent_i_
;
148 comment_mode_b_
= false;
151 handle_pending_indent();
160 Mudela_stream::output_wrapped (String str
)
162 // enough room left -> doit
163 if (column_i_
+ str
.length_i() <= wrap_column_i_
)
169 // we're at BOL already; this will never fit -> doit
170 if (column_i_
== indent_i_
* INDENT_i
)
177 // preserve comment mode
179 output (String ("\n%"));
181 output (String ("\n"));