source: trunk/MagicSoft/Mars/mbase/MLogHtml.cc@ 9579

Last change on this file since 9579 was 8767, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 3.7 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25
26//////////////////////////////////////////////////////////////////////////////
27//
28// MLogHtml
29//
30//////////////////////////////////////////////////////////////////////////////
31#include "MLogHtml.h"
32
33#include <string.h> // necessary for Fedora core 2 with kernel 2.6.9-1.667 #1 and gcc 3.4.2
34#include <errno.h> // necessary for Fedora core 2 with kernel 2.6.9-1.667 #1 and gcc 3.4.2
35
36#include <fstream> // ofstream
37#include <iostream> // cout
38
39#include "MTime.h"
40
41ClassImp(MLogHtml);
42
43using namespace std;
44
45MLogHtml::MLogHtml(const char *name) : fUnderline(0), fColor(-1)
46{
47 fOut = new ofstream(name);
48 if (!*fOut)
49 {
50 delete fOut;
51 fOut = NULL;
52
53 cerr << "Cannot open file " << name << ": " << strerror(errno) << endl;
54 return;
55 }
56
57 // switch off buffering
58 fOut->rdbuf()->pubsetbuf(0,0);
59
60 MTime time;
61 time.Now();
62
63 *fOut << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" << endl;
64 *fOut << endl;
65 *fOut << "<html>" << endl;
66 *fOut << "<head>" << endl;
67 *fOut << " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">" << endl;
68 *fOut << " <meta name=\"Author\" content=\"Mars-MLogHtml" << MARSVER << "\">" << endl;
69 *fOut << " <title>MARS - Logging, created " << time << "</title>" << endl;
70 *fOut << "</head>" << endl;
71 *fOut << endl;
72 *fOut << "<pre>" << endl;
73 //*fOut << "<body background=\"background.gif" text="#000000" bgcolor="#000099" link="#1122FF" vlink="#8888FF" alink="#FF0000">
74}
75
76MLogHtml::~MLogHtml()
77{
78 if (!fOut)
79 return;
80
81 *fOut << "</font>" << endl;
82 *fOut << "</pre>" << endl;
83 *fOut << endl;
84 *fOut << "</html>" << endl;
85
86 delete fOut;
87}
88
89void MLogHtml::Underline()
90{
91 if (!fOut)
92 return;
93
94 *fOut << "<u>";
95 fUnderline = kTRUE;
96}
97
98void MLogHtml::SetColor(Int_t col)
99{
100 if (!fOut)
101 return;
102
103 if (fColor>0 && fColor!=col)
104 *fOut << "</font>";
105
106 if (fColor==col)
107 return;
108
109 switch (col)
110 {
111 case 0: break;
112 case 1: *fOut << "<font color='maroon'>"; break; // err
113 case 2: *fOut << "<font color='#FF6600'>"; break; // warn (olive?)
114 case 3: // inf
115 case 4: // inf2
116 case 5: *fOut << "<font color='green'>"; break; // inf3
117 default: *fOut << "<font color='navy'>"; break; // all others (dbg)
118 }
119
120 fColor=col;
121}
122
123void MLogHtml::WriteBuffer(const char *str, int len)
124{
125 if (!fOut)
126 {
127 cout.write(str, len);
128 return;
129 }
130
131 TString txt(str, len);
132
133 txt.ReplaceAll(">", "&gt;");
134 txt.ReplaceAll("<", "&lt;");
135
136 fOut->write(txt.Data(), txt.Length());
137 if (fUnderline)
138 {
139 *fOut << "</u>";
140 fUnderline = kFALSE;
141 }
142}
Note: See TracBrowser for help on using the repository browser.