Commit 09bf7bd9 authored by Martin Marinov's avatar Martin Marinov
Browse files

Fixed various issues with Debug printing on the console.

parent 45268903
......@@ -48,10 +48,9 @@ public:
public:
Impl(const char* const _flnm, const uint _flags = APPEND | RETAIN)
: flags_(_flags), num_flush_(0), indt_(2), at_line_start_(false)
: flags_(_flags), num_flush_(0), line_strt_(false)
{
set_filename(_flnm);
}
~Impl()
......@@ -96,16 +95,6 @@ public:
return priority_;
}
bool fork_to_cout()
{
return false;
}
bool fork_to_cerr()
{
return true;
}
const char* filename() const
{
if (this && (!flnm_.empty())) return flnm_.c_str();
......@@ -119,93 +108,34 @@ public:
flnm_.clear();
}
char prev_char() const
void print(const char _c, const bool _cnsl = true)
{
if (!bffr_.empty())
return *bffr_.rbegin();
if (!output_.empty())
return *output_.rbegin();
return '\0';
}
void indent(bool /*_full_text*/) { bffr_.append(indt_, ' '); }
void line_break(bool _with_indent = false)
{
if (is_html())
bffr_.append("<br>"); // Don't bother with matching </br>
bffr_.append(1, '\n');
if (_with_indent)
indent(false);
else
at_line_start_ = true;
}
void print_direct(const std::string& _s)
{
bffr_.append(_s);
}
void print(const char _c)
{
if (_c == '\n')
{
line_break();
return;
}
if (at_line_start_)
if (line_strt_)
{
indent(true);
at_line_start_ = false;
}
if (is_html())
{
// translate the esoteric characters used in IGM DEB_out
if (_c == -62 ) // -62
return;
if (_c == -89) // 167 = -89
{
bffr_.append("&sect;");
return;
}
if (_c == -80) // -80
{
bffr_.append("&deg;");
return;
}
line_strt_ = false;
print(' ', false); // indents never go onto the console!
}
bffr_.append(&_c, 1);
if (_cnsl)
std::cout << _c; // print on the console
if (_c == '\n')
line_strt_ = true;
}
void print_to_ostream(const char* const _s, std::ostream& os)
void line_break(const bool _cnsl = true) { print('\n', _cnsl); }
void print(const std::string& _s, const bool _cnsl = true)
{
os << _s;
for (size_t i = 0, n = _s.size(); i < n; ++i)
print(_s[i], _cnsl);
}
void print(const char* const _s, bool _fork = true)
void print(const char* const _s, const bool _cnsl = true)
{
if (_s != NULL)
{
for (int i = 0; ; ++i)
{
const char c = _s[i];
if (c == '\0') break;
print(c);
}
if (_fork)
{
if (fork_to_cout())
print_to_ostream(_s, std::cout);
if (fork_to_cerr())
print_to_ostream(_s, std::cerr);
}
}
if (_s == nullptr)
return;
for (int i = 0, c = _s[0]; c != '\0'; c = _s[++i])
print((char)c, _cnsl);
}
void print(const size_t _i)
......@@ -254,23 +184,10 @@ public:
switch (_co.cmd)
{
case Base::Command::END :
if (is_html()) print_direct("</FONT>");
break;
case Base::Command::END_ERR :
// Powerdown DEB_error font
// if (is_html()) print_direct("</BLINK>");
// fall through
case Base::Command::END_LF :
if (is_html()) print_direct("</FONT>");
line_break();
// line_break() does not fork to cout or cerr
// so do so explicitly.
if (fork_to_cout())
std::cout << "\n";
if (fork_to_cerr())
std::cerr << "\n";
break;
}
}
......@@ -373,25 +290,16 @@ public:
void footer()
{
bool date_footer = true;
if (date_footer)
{
std::string str("\n");
if (!flnm_.empty()) str.append(flnm_);
str.append(" Closed: ");
add_time(str);
str.append("\n");
print(str.c_str());
}
if (is_html())
print("\n</BODY></HTML>", false);
std::string str("\n");
if (!flnm_.empty())
str.append(flnm_);
str.append(" Closed: ");
add_time(str);
str.append("\n");
print(str.c_str());
}
bool is_first_flush()
{
return num_flush_ == 0 ;
}
bool is_first_flush() { return num_flush_ == 0; }
bool flush()
{
......@@ -456,31 +364,19 @@ public:
flags_ = flags_ | HTML;
}
bool is_at_line_start()
{
return at_line_start_;
}
void enter(const int _id)
void enter()
{
const bool entr_cnsl = false; // do we print enters on the console?
// First DEB_out in this function so output call-stack, and flush.
if (!line_strt_)
line_break(entr_cnsl); // make sure we start on a new line with this
std::string str;
if (is_html())
{
str.append("<FONT SIZE=2><u>");
anchor(str, _id, "enter", true);
}
else
str.append("*>"); // .txt call stack lead in
str.append("*>"); // .txt call stack lead in
CallStack::query().append(str);
bffr_.append(str);
if (is_html())
str.append("</u></FONT>");
print_direct(str.c_str()); // Don't fork call-stack to cerr etc.
line_break();
line_break(entr_cnsl); // make sure we start on a new line with this
flush();
}
......@@ -488,9 +384,7 @@ private:
uint flags_;
int num_flush_;
int priority_; // Last permission granted
size_t indt_;
bool at_line_start_;
bool line_strt_; // are we at the start of th line?
std::string bffr_;
std::string output_;
......@@ -518,7 +412,7 @@ File::~File()
delete impl_;
}
void File::enter(const int _id) { impl_->enter(_id); }
void File::enter(const int /*_id*/) { impl_->enter(/*_id*/); }
void File::print(const char _c) { impl_->print(_c); }
void File::print(const char* _s) { impl_->print(_s); }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment