17 #include "StMessage.h"
18 #include "StMessageCounter.h"
20 #include "StMessageStream.h"
24 static char space =
' ';
25 static char tab =
'\t';
27 int StMessage::repeats=1;
28 static std::ostringstream lastMessBuffer;
35 StMessage::StMessage(
const char *mess,
const char *ty,
const char* opt) {
42 int len = strlen(mess);
43 while (mess[--len] == space) {}
44 message =
new char[(++len + 1)];
45 for (
int i=0;i<len;i++) {
47 if (mess[i]==
'\n')
continue;
48 if (mess[i]==
'\t')
continue;
49 if (!iscntrl(mess[i]))
continue;
56 StMessage::~StMessage() {
60 int StMessage::Print(
int nChars) {
65 static const char* leader =
"St";
66 static const char* insert0 =
"";
67 static const char* insert1 =
": ";
68 static const char* insert2 =
" <";
69 static const char* insert3 =
">";
70 static const char* endofline =
"\n";
73 printIt = messCounter->CheckLimit(message,type);
75 std::ostringstream messBuffer;
78 if (!(option & kMessOptP)) {
79 if (!(option & kMessOptS)) messBuffer << leader;
80 const char* temp(StMessTypeList::Instance()->Text(type));
81 if (temp) messBuffer << temp;
83 }
else insert = insert0;
84 if ((nChars != 0) && (strchr(message,tab))) {
85 char* message2 =
new char[strlen(message)+1];
89 if (*m0==tab) *m1 = space;
94 messBuffer << insert << message2;
97 messBuffer << insert << message;
100 if (option & kMessOptT) {
101 char* temp2 = (ctime(&messTime) + 4);
103 messBuffer << insert2 << temp2 << insert3 ;
105 messBuffer << endofline;
108 bool addedMessageFlag =
false;
109 std::string addedMessage;
111 addedMessageFlag =
true;
112 addedMessage = messCounter->str();
115 if (messBuffer.tellp() >= nChars)
116 messBuffer.seekp(nChars-1);
117 int noReturns = strcspn(messBuffer.str().c_str(),endofline);
118 if (noReturns < messBuffer.tellp()) messBuffer.seekp(noReturns);
123 if (!strcmp(messBuffer.str().c_str(),lastMessBuffer.str().c_str())) {
124 return messBuffer.tellp();
126 lastMessBuffer.seekp(0);
127 lastMessBuffer << messBuffer.str() << ends;
130 if ((option & kMessOptO) || (nChars != 0)) {
131 myout << messBuffer.str();
132 if (addedMessageFlag) myout << addedMessage;
135 if ((option & kMessOptE) && (nChars == 0)) {
136 myerr << messBuffer.str();
137 if (addedMessageFlag) myerr << addedMessage;
140 return messBuffer.tellp();
143 char* StMessage::GetOptions()
const {
144 static char optStr[32];
146 if (option & kMessOptO) sprintf(sPtr++,
"%c",
'O');
147 if (option & kMessOptE) sprintf(sPtr++,
"%c",
'E');
148 if (option & kMessOptS) sprintf(sPtr++,
"%c",
'S');
149 if (option & kMessOptT) sprintf(sPtr++,
"%c",
'T');
150 if (option & kMessOptP) sprintf(sPtr++,
"%c",
'P');
151 if (option & kMessOptDash) sprintf(sPtr++,
"%c",
'-');
156 void StMessage::SetOptions(
const char* opt) {
157 option = kMessOptNone;
159 int len = strlen(opt);
161 switch (toupper(opt[len])) {
162 case (
'O') : { option |= kMessOptO;
break; }
163 case (
'E') : { option |= kMessOptE;
break; }
164 case (
'S') : { option |= kMessOptS;
break; }
165 case (
'T') : { option |= kMessOptT;
break; }
166 case (
'P') : { option |= kMessOptP;
break; }
167 case (
'-') : { option |= kMessOptDash;
break; }
173 size_t StMessage::GetMemoryUsage() {
174 size_t msize = strlen(message) + 1;
175 msize +=
sizeof(*this);
179 void StMessage::PrintInfo() {
180 printf(
"**************************************************************\n");
181 printf(
"* $Id: StMessage.cxx,v 1.29 2016/06/14 06:24:54 genevb Exp $\n");
183 printf(
"**************************************************************\n");