It counts braces to prevent nesting errors, and
it will add a comment sign before each newline.
*/
-struct Tex_stream {
+class Tex_stream {
+ void break_line();
+public:
bool outputting_comment;
ostream *os;
int nest_level;
+ /// to check linelen in output. TeX has limits.
+ int line_len_i_;
/// open a file for writing
Tex_stream(String filename);
#include "tex-stream.hh"
#include "debug.hh"
+const int MAXLINELEN = 200;
+
Tex_stream::Tex_stream(String filename)
{
os = new ofstream(filename);
if (!*os)
error("can't open `" + filename+"\'");
nest_level = 0;
+ line_len_i_ = 0;
outputting_comment=false;
header();
}
}
continue;
}
+ line_len_i_ ++;
switch(*cp)
{
case '%':
/* FALLTHROUGH */
case '\n':
- *os << "%\n";
- *os << String(' ', nest_level);
+ break_line();
break;
+ case ' ':
+ *os << ' ';
+ if (line_len_i_ > MAXLINELEN)
+ break_line();
+
+ break;
default:
*os << *cp;
break;
return *this;
}
+void
+Tex_stream::break_line()
+{
+ *os << "%\n";
+ *os << String(' ', nest_level);
+ line_len_i_ = 0;
+}
/* *************************************************************** */