16 #include "TObjArray.h"
24 TDirIter::TDirIter(
const char *path,Int_t maxlev):fRegx(
"",0)
37 void TDirIter::Reset(
const char *path,Int_t maxlev)
44 FILE *in = fopen(path+1,
"r");
46 fprintf(stderr,
"*** TDirIter::Reset failed to open %s ***\n",path+1);
52 while ( fgets(buf,1024,in) ) {
53 if (*buf ==
'!')
continue;
54 if (*buf ==
'#')
continue;
56 char *c = strchr(buf,
' ');
74 fSkip = strspn(fFull.Data(),
" \t\n");
75 ResetQQ(fFull.Data()+fSkip);
78 void TDirIter::ResetQQ(
const char *path)
80 TString machine(
"root://");
81 machine += gSystem->HostName();
83 fLevel = 0; fState = 1; fSele=0; fTop = 0;
85 int n = strcspn(path,
" \t\n");
86 TString myPath; myPath.Insert(0,path,n);
87 gSystem->ExpandPathName(myPath);
90 const char *p = myPath.Data();
93 if (fFile.BeginsWith(machine)) {
94 fFile.ReplaceAll(machine,
"");
96 fFile.ReplaceAll(
".gov//",
".gov:1095//");
98 const char *c,*f=fFile.Data();
99 c = strpbrk(f,
"*#?[]\\");
101 fSele=1;fFile.Remove(c-f,9999);
102 int s = fFile.Last(
'/');
103 if (s>0) {fFile.Remove(s,9999);}
106 if (fFile.Length()==0) f =
".";
108 Long_t flags = 0,
id = 0, modtime = 0; Long64_t size=1;
110 if (! strstr(f,
"://"))
111 noexi = gSystem->GetPathInfo(f,&
id,&size,&flags,&modtime);
114 Warning(
"TDirIter",
"*** File %s does not exist ***",f);}
117 Warning(
"TDirIter",
"*** File %s is empty ***",f);}
118 else if ((flags&2)==0) {
120 Warning(
"TDirIter",
"*** File %s is special (like socket) ***",f);}
123 fTop = fFile.Length();
124 if (myPath[0]==
'^') fTop = 0;
125 TString QWE = MakeWild(myPath.Data()+fTop);
129 int lP = myPath.Length();
130 if (lP && *p!=
'^' && strstr(p,
"#")==0) {
132 for(
int i=fTop+1;i<lP;i++) {
if (p[i]==
'/') fMaxLevQQ++; } }
135 const char *TDirIter::NextFile()
139 while((name=NextFileQ())) {fArr->Add(
new TNamed(name,
""));}
143 if (fIter > fArr->GetLast())
return 0;
144 return fArr->At(fIter)->GetName();
148 const char *TDirIter::NextFileQ()
151 const char *name = NextFileQQ();
152 if (name)
return name;
153 const char *full = fFull.Data();
154 if (full[fSkip]==0)
return 0;
155 fSkip += strcspn(full+fSkip,
" \t\n");
156 if (full[fSkip]==0)
return 0;
157 fSkip += strspn(full+fSkip,
" \t\n");
158 if (full[fSkip]==0)
return 0;
164 const char *TDirIter::NextFileQQ()
166 if (fSele == -2)
return 0;
167 if (fSele == -1) {fSele = -2;
return fFile.Data();}
169 if (fState && fLevel < fMaxLevQQ) {
171 const char *f = fFile.Data();
173 fEntrStk[fLevel] = gSystem->OpenDirectory(f);
174 fLengStk[fLevel] = fFile.Length();
178 while ((name = gSystem->GetDirEntry(fEntrStk[fLevel])))
180 if (strcmp(
"." ,name)==0)
continue;
181 if (strcmp(
"..",name)==0)
continue;
185 gSystem->FreeDirectory(fEntrStk[fLevel]);
186 if (fLevel<=0)
return 0;
191 fFile.Remove(fLengStk[fLevel],999);
192 if (fFile.Length()) fFile +=
"/"; fFile += name;
193 Long_t flags=0; fState=0;
194 Long_t
id = 0, modtime = 0;Long64_t size=0;
195 if (strstr(fFile.Data(),
"://")==0)
196 gSystem->GetPathInfo(fFile.Data(),&id,&size,&flags,&modtime);
197 if (flags & 2) fState=1;
200 TString qwe(fFile.Data()+fTop);
201 if (fRegx.Index(qwe,&len) >=0)
break;
207 TString TDirIter::MakeWild(
const char *re)
210 if (re[0]==
'^') { ts = re;
return ts;}
212 for (
int i=0;re[i];i++)
214 if (i == 0) {ts+=
"^" ;}
215 if (re[i]==
'*') {ts+=
"[a-zA-Z0-9_\\.,-= ]*";
continue;}
216 if (re[i]==
'#') {ts+=
".*";
continue;}
217 if (re[i] ==
'.') {ts+=
"\\.";
continue;}