35 if ( !expandEnvVars( filename ) ) {
37 <<
"Error while expanding environment variables in file name '" 38 << filename.c_str() <<
"'" << endl;
42 _fin.open( filename.c_str() );
45 <<
"Could not open file '" << filename.c_str() <<
"'" << endl;
60 if ( !processTagTree() ) {
62 <<
"Unexpected end tag " << _tagTitle <<
" found near line " 65 <<
"Will terminate execution!" << endl;
69 while ( _line.find(
"<" ) ==
72 if ( !std::getline( _fin, addLine ) )
79 unsigned int startTag;
81 unsigned int endTagTitle;
83 startTag = _line.find(
"<" );
85 if ( _line[startTag + 1] ==
87 while ( _line.find(
"?>", startTag ) == std::string::npos ) {
89 if ( !std::getline( _fin, addLine ) )
95 endTag = _line.find(
"?>", startTag );
96 _line = _line.substr( endTag + 2 );
98 }
else if ( _line[startTag + 1] ==
100 while ( _line.find(
"-->", startTag ) == std::string::npos ) {
102 if ( !std::getline( _fin, addLine ) )
108 endTag = _line.find(
"-->", startTag );
109 _line = _line.substr( endTag + 3 );
112 return readNextTag();
115 while ( _line.find(
">", startTag ) ==
116 std::string::npos ) {
118 if ( !std::getline( _fin, addLine ) )
124 endTag = _line.find(
">", startTag );
126 if ( _line.find(
"/>", startTag ) < endTag ) {
131 if ( _line.find(
" ", startTag ) != std::string::npos &&
132 _line.find(
" ", startTag ) <
134 endTagTitle = _line.find(
" ", startTag );
136 endTagTitle = endTag;
139 _tagTitle = _line.substr( startTag + 1, endTagTitle - startTag - 1 );
140 _tag = _line.substr( startTag + 1, endTag - startTag - 1 );
144 _line = _line.substr( endTag + 2 );
146 _line = _line.substr( endTag + 1 );
154 if ( _tagTree.empty() )
157 return _tagTree.back();
161 std::string defaultValue )
163 std::string whitespace =
" \t\n\v\f\r";
164 for (
unsigned int i = 0; i < whitespace.size(); i++ ) {
166 std::string attName = whitespace[i] + attribute +
"=";
167 if ( _tag.find( attName ) != std::string::npos ) {
168 int startAttri = _tag.find( attName );
169 int startQuote = _tag.find(
"\"", startAttri + 1 );
170 int endQuote = _tag.find(
"\"", startQuote + 1 );
171 return _tag.substr( startQuote + 1, endQuote - startQuote - 1 );
179 std::string valStr = readAttribute( attribute );
181 return ( valStr ==
"true" || valStr ==
"1" || valStr ==
"on" ||
184 return ( valStr !=
"false" && valStr !=
"0" && valStr !=
"off" &&
190 std::string valStr = readAttribute( attribute );
193 std::istringstream valStream( valStr );
200 double defaultValue )
202 std::string valStr = readAttribute( attribute );
205 std::istringstream valStream( valStr );
213 if ( _tagTitle ==
"" )
215 if ( _tagTitle[0] ==
'/' ) {
216 if ( _tagTitle.substr( 1 ) == _tagTree.back() ) {
221 }
else if ( !_inLineTag ) {
222 _tagTree.push_back( _tagTitle );
229 while ( str.find(
'$' ) != std::string::npos ) {
230 size_t varStart = str.find(
'$' );
231 size_t varNameLength;
235 if ( varStart == str.length() - 1 ) {
236 str.erase( varStart );
240 if ( str[varStart + 1] ==
'{' ) {
242 size_t braceStart = varStart + 1;
243 size_t braceEnd = str.find(
'}', braceStart );
245 if ( braceEnd == std::string::npos ) {
247 <<
"Incomplete environment variable found in text: " << str
250 <<
"Will terminate execution!" << endl;
254 varName = str.substr( braceStart + 1, braceEnd - braceStart - 1 );
255 varNameLength = braceEnd - varStart;
261 while ( varNameLength + varStart + 1 < str.length() &&
262 isAlphaNum( str[varStart + varNameLength + 1] ) ) {
266 varName = str.substr( varStart + 1, varNameLength );
269 char* envVar = getenv( varName.c_str() );
272 str.replace( varStart, varNameLength + 1, envVar );
275 <<
"Undefined environment variable found in text: " << varName
277 str.replace( varStart, varNameLength + 1,
"" );
285 if ( c >=
'0' && c <=
'9' )
287 if ( c >=
'A' && c <=
'Z' )
289 if ( c >=
'a' && c <=
'z' )
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=0)
double readAttributeDouble(std::string attribute, double defaultValue=-1.)
bool open(std::string filename)
bool readAttributeBool(std::string attribute, bool defaultValue=false)
std::string getParentTagTitle()
int readAttributeInt(std::string attribute, int defaultValue=-1)
bool expandEnvVars(std::string &str)
std::string readAttribute(std::string attribute, std::string defaultValue="")