source: tags/Mars-V0.10.3/mbase/MLogHtml.cc

Last change on this file was 8051, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 3.6 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=#aa0000>"; break; // err
113 case 2: *fOut << "<font color=#00aaaa>"; break; // warn
114 case 3: *fOut << "<font color=#00aa00>"; break; // inf
115 default: *fOut << "<font color=#0000aa>"; break; // all others (dbg)
116 }
117
118 fColor=col;
119}
120
121void MLogHtml::WriteBuffer(const char *str, int len)
122{
123 if (!fOut)
124 {
125 cout.write(str, len);
126 return;
127 }
128
129 TString txt(str, len);
130
131 txt.ReplaceAll(">", "&gt;");
132 txt.ReplaceAll("<", "&lt;");
133
134 fOut->write(txt.Data(), txt.Length());
135 if (fUnderline)
136 {
137 *fOut << "</u>";
138 fUnderline = kFALSE;
139 }
140}
Note: See TracBrowser for help on using the repository browser.