Changeset 13078
- Timestamp:
- 03/13/12 10:48:55 (13 years ago)
- Location:
- trunk/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mbase/MDirIter.cc
r9441 r13078 63 63 #include "MDirIter.h" 64 64 65 #include <fstream> 65 66 #include <iostream> 66 67 … … 68 69 #include <TNamed.h> 69 70 #include <TRegexp.h> 71 #include <TPRegexp.h> 70 72 #include <TSystem.h> 73 74 #include "MLog.h" 75 #include "MLogManip.h" 71 76 72 77 ClassImp(MDirIter); … … 171 176 } 172 177 178 Int_t MDirIter::ReadList(const char *name) 179 { 180 TString fname(name); 181 gSystem->ExpandPathName(fname); 182 183 ifstream fin(fname); 184 if (!fin) 185 { 186 gLog << err << "Cannot open file " << fname << ": "; 187 gLog << strerror(errno) << " [errno=" << errno << "]" <<endl; 188 return -1; 189 } 190 191 Int_t rc = 0; 192 193 while (1) 194 { 195 TString line; 196 line.ReadLine(fin); 197 if (!fin) 198 break; 199 200 line = line.Strip(TString::kBoth); 201 if (line[0]=='#' || line.IsNull()) 202 continue; 203 204 TObjArray &arr = *line.Tokenize(' '); 205 206 for (int i=1; i<arr.GetEntries(); i++) 207 rc += AddDirectory(arr[0]->GetName(), arr[i]->GetName(), -1); 208 209 delete &arr; 210 } 211 212 return true; 213 } 214 173 215 // -------------------------------------------------------------------------- 174 216 // … … 211 253 212 254 // -------------------------------------------------------------------------- 255 // 256 // Check whether the given name n matches the filter f. 257 // 258 // If the filter is encapsulated in ^ and $ it is assumed to be 259 // a valid regular expression and TPRegexp is used for filtering. 260 // 261 // In other cases TRegex is used: 213 262 // 214 263 // As the filter string may contain a + character, we have to replace … … 220 269 // + by \\+ 221 270 // * by [^\\/:]* 222 // ? by .223 271 // 224 272 // And surround the filter by ^ and $. … … 227 275 // TRegexp::MakeWildcard 228 276 // 229 const TRegexp MDirIter::MakeRegexp(TString n) const 230 { 231 n.Prepend("^"); 232 n.ReplaceAll(".", "\\."); 233 n.ReplaceAll("+", "\\+"); 234 n.ReplaceAll("*", "[^\\/:]*"); 235 n.Append("$"); 236 237 return TRegexp(n, kFALSE); 238 } 239 240 // -------------------------------------------------------------------------- 241 // 242 // Check whether the given name n matches the filter f. 243 // Filters are of the form TRegexp(f, kTRUE) 244 // 245 Bool_t MDirIter::MatchFilter(const TString &n, const TString &f) const 246 { 247 248 return f.IsNull() || !n(MakeRegexp(f)).IsNull(); 277 Bool_t MDirIter::MatchFilter(const TString &n, TString f) const 278 { 279 if (f.IsNull()) 280 return kTRUE; 281 282 if (f[0]=='^' && f[f.Length()-1]=='$') 283 { 284 TPRegexp regex(f); 285 return !n(regex).IsNull(); 286 } 287 288 f.Prepend("^"); 289 f.ReplaceAll(".", "\\."); 290 f.ReplaceAll("+", "\\+"); 291 f.ReplaceAll("*", "[^\\/:]*"); 292 //f.ReplaceAll("?", "[^\\/:]?"); 293 f.Append("$"); 294 295 return !n(TRegexp(f)).IsNull(); 249 296 } 250 297 -
trunk/Mars/mbase/MDirIter.h
r9441 r13078 20 20 Bool_t CheckEntry(const TString n) const; 21 21 Int_t IsDir(const char *dir) const; 22 Bool_t MatchFilter(const TString &name, const TString &filter) const;22 Bool_t MatchFilter(const TString &name, TString filter) const; 23 23 TString ConcatFileName(const char *dir, const char *name) const; 24 24 void PrintEntry(const TObject &o) const; 25 const TRegexp MakeRegexp(TString n) const;26 25 27 26 public: … … 49 48 } 50 49 50 Int_t ReadList(const char *fname); 51 51 void Sort(); 52 52
Note:
See TracChangeset
for help on using the changeset viewer.