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

Last change on this file since 7710 was 7632, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 3.5 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 MTime time;
58 time.Now();
59
60 *fOut << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" << endl;
61 *fOut << endl;
62 *fOut << "<html>" << endl;
63 *fOut << "<head>" << endl;
64 *fOut << " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">" << endl;
65 *fOut << " <meta name=\"Author\" content=\"Mars-MLogHtml" << MARSVER << "\">" << endl;
66 *fOut << " <title>MARS - Logging, created " << time << "</title>" << endl;
67 *fOut << "</head>" << endl;
68 *fOut << endl;
69 *fOut << "<pre>" << endl;
70 //*fOut << "<body background=\"background.gif" text="#000000" bgcolor="#000099" link="#1122FF" vlink="#8888FF" alink="#FF0000">
71}
72
73MLogHtml::~MLogHtml()
74{
75 if (!fOut)
76 return;
77
78 *fOut << "</font>" << endl;
79 *fOut << "</pre>" << endl;
80 *fOut << endl;
81 *fOut << "</html>" << endl;
82
83 delete fOut;
84}
85
86void MLogHtml::Underline()
87{
88 if (!fOut)
89 return;
90
91 *fOut << "<u>";
92 fUnderline = kTRUE;
93}
94
95void MLogHtml::SetColor(Int_t col)
96{
97 if (!fOut)
98 return;
99
100 if (fColor>0 && fColor!=col)
101 *fOut << "</font>";
102
103 if (fColor==col)
104 return;
105
106 switch (col)
107 {
108 case 0: break;
109 case 1: *fOut << "<font color=#aa0000>"; break; // err
110 case 2: *fOut << "<font color=#00aaaa>"; break; // warn
111 case 3: *fOut << "<font color=#00aa00>"; break; // inf
112 default: *fOut << "<font color=#0000aa>"; break; // all others (dbg)
113 }
114
115 fColor=col;
116}
117
118void MLogHtml::WriteBuffer(const char *str, int len)
119{
120 if (!fOut)
121 {
122 cout.write(str, len);
123 return;
124 }
125
126 TString txt(str);
127
128 txt.ReplaceAll(">", "&gt;");
129 txt.ReplaceAll("<", "&lt;");
130
131 fOut->write(txt.Data(), len);
132 if (fUnderline)
133 {
134 *fOut << "</u>";
135 fUnderline = kFALSE;
136 }
137}
Note: See TracBrowser for help on using the repository browser.