Changeset 18018 for trunk/Mars
- Timestamp:
- 11/17/14 18:42:01 (10 years ago)
- Location:
- trunk/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mbase/MEnv.cc
r9345 r18018 51 51 #include "MEnv.h" 52 52 53 #include <fstream> 54 #include <exception> 55 53 56 #include <Gtypes.h> 54 57 #include <TObjString.h> … … 97 100 98 101 SetRcName(fname); 102 103 if (!IsTEnvCompliant(name)){ 104 throw "This file can't be correctly parsed by TEnv"; 105 return; 106 } 99 107 100 108 // No file found … … 189 197 190 198 return 0; 199 } 200 201 //--------------------------------------------------------------------------- 202 // 203 // Check if the input file is compatible to the way TEnv parses a resource file. 204 // 205 // Returns true in case everything is file and 206 // false in case there is a problem with the file. 207 // 208 // Background: 209 // This check has been introduced as a workaround for a ROOT feature. 210 // TEnv will not see the last line in a text file, when this last line 211 // does not end with a \n. 212 // 213 // In addition we check for the occurence of \r, since some editors would 214 // place \r instead of \n (unlike windows that uses \n\r), which would 215 // also result in problems. 216 // FIXME: So currently we also complain about "\n\r" and "\r\n" as well as 217 // "\r \t \n" or "\n \t\t\t\r", which would in fact not be a problem at 218 // all. 219 Bool_t MEnv::IsTEnvCompliant(const char *fname) 220 { 221 ifstream ifs(fname); 222 bool printable_char_since_last_lf = false; 223 char c; 224 while (ifs.good()){ 225 ifs.get(c); 226 227 if (c==13){ 228 gLog << err << "Menv::IsTEnvCompliant - file:" << fname 229 << " contains \\r this might lead to parsing errors. " 230 <<"Please exchange \\r by \\n everywhere in that file." 231 << endl; 232 return false; 233 } 234 if (c=='\n'){ 235 printable_char_since_last_lf = false; 236 } 237 if (isgraph(c)){ 238 printable_char_since_last_lf = true; 239 } 240 } 241 if (printable_char_since_last_lf){ 242 gLog << err << "Menv::IsTEnvCompliant - file:" << fname 243 << " must have \\n at the end of the file. " 244 <<"Please make sure this is the case." 245 << endl; 246 return false; 247 } 248 return true; 191 249 } 192 250 -
trunk/Mars/mbase/MEnv.h
r9518 r18018 27 27 TString Compile(TString str, const char *post) const; 28 28 Int_t ReadInclude(); 29 Bool_t IsTEnvCompliant(const char *fname); 29 30 30 31 public:
Note:
See TracChangeset
for help on using the changeset viewer.