Files Classes Functions Hierarchy
#include <pathstuff.h>
Public Member Functions | |
| void | convert (string &s, vector< string > const &path) const |
| void | convert (vector< string > &v, string const &path) const |
| void | convert (rpnprogram &p, vector< string > const &path) const |
| void | convert (vector< string > &path, rpnprogram const &p) const |
| void | contains (bool &res, vector< string > const &path, string const &targ) |
| void | findrelativetree (bool &found, rpnprogram *&prog, rpnprogram *const current, vector< string > const &pathtree) |
| void | findrelativetree (bool &found, deque< rpnprogram * > &programlist, rpnprogram *const current, vector< string > const &pathtree) |
| void | resolveparent (bool &valid, vector< string > &path, vector< string > const &path0) |
| void | pwd (vector< string > &v) |
| void | findpath (bool &found, rpnprogram *&prog, vector< string > const &path) |
| void | findpath (bool &found, deque< rpnprogram * > &programlist, vector< string > const &path) |
| void | absolute (bool &found, vector< string > &pathfromhome, vector< string > const &path) |
| bool const | ispurerelative (vector< string > const &path) |
Static Public Attributes | |
| static string const | root = "/" |
| static string const | fwdsep = "/" |
| static string const | parent = ".." |
Definition at line 13 of file pathstuff.h.
| void pathstuff::absolute | ( | bool & | found, | |
| vector< string > & | pathfromhome, | |||
| vector< string > const & | path | |||
| ) |
Definition at line 415 of file pathstuff.cpp.
00420 { 00421 found = false; 00422 00423 if (path.empty()) 00424 return; 00425 00426 vector<string> v(path); 00427 vector<string> v2; 00428 00429 /* Make the path be relative to the home directory. */ 00430 if (v[0] != root) 00431 { 00432 pwd(v2); 00433 ::copy(v.begin(),v.end(),back_inserter(v2)); 00434 } 00435 else 00436 v2 = v; 00437 00438 #ifdef DEBUG_PATHSTUFF 00439 string t; 00440 convert(t,v2); 00441 cout << "~:" << t << endl; 00442 #endif 00443 00444 /* Realize the path, resolving .. . */ 00445 resolveparent(found,pathfromhome,v2); 00446 }
| void pathstuff::contains | ( | bool & | res, | |
| vector< string > const & | path, | |||
| string const & | targ | |||
| ) |
Definition at line 201 of file pathstuff.cpp.
Referenced by ispurerelative().
00206 { 00207 res = false; 00208 00209 if (path.empty()) 00210 return; 00211 00212 for (unsigned int i=0, imax=path.size(); i<imax; ++i) 00213 { 00214 if (path[i]==targ) 00215 { 00216 res = true; 00217 return; 00218 } 00219 } 00220 }
| void pathstuff::convert | ( | vector< string > & | path, | |
| rpnprogram const & | p | |||
| ) | const |
Definition at line 281 of file pathstuff.cpp.
References rpnbase::isstring(), and rpnprogram::v.
00282 { 00283 path.clear(); 00284 00285 if (p.v.empty()) 00286 return; 00287 00288 path.resize( p.v.size() ); 00289 00290 /* Verify that each element is an rpnstring. */ 00291 rpnbase* w; 00292 for (unsigned int i=0, imax=p.v.size(); i<imax; ++i) 00293 { 00294 w = p.v[i]; 00295 if (!w->isstring()) 00296 { 00297 path.clear(); 00298 return; 00299 } 00300 00301 path[i] = ((rpnstring*)w)->str; 00302 } 00303 00304 }
| void pathstuff::convert | ( | rpnprogram & | p, | |
| vector< string > const & | path | |||
| ) | const |
Definition at line 261 of file pathstuff.cpp.
References rpnstring::str, and rpnprogram::v.
00262 { 00263 if (!p.v.empty()) 00264 return; 00265 00266 if (path.empty()) 00267 return; 00268 00269 unsigned int imax = path.size(); 00270 p.v.resize(imax); 00271 rpnstring *w; 00272 for (unsigned int i=0; i<imax; ++i) 00273 { 00274 00275 p.v[i] = w = new rpnstring(); 00276 w->str = path[i]; 00277 } 00278 00279 }
| void pathstuff::convert | ( | vector< string > & | v, | |
| string const & | path | |||
| ) | const |
Definition at line 223 of file pathstuff.cpp.
References root.
00224 { 00225 assert(false); 00226 00227 // TODO - looking at alternative 00228 // tokenizer tk(path); 00229 // tk.subtract(fwdsep); 00230 00231 // Commented out non-existing function. 00232 // linesplit(v,path,fwdsep); 00233 if( path[0]=='/') 00234 v.insert(v.begin(),root); 00235 }
| void pathstuff::convert | ( | string & | s, | |
| vector< string > const & | path | |||
| ) | const |
Definition at line 237 of file pathstuff.cpp.
Referenced by pwd().
00238 { 00239 vector<string> path(pth); 00240 00241 s = ""; 00242 if (path.empty()) 00243 return; 00244 00245 s = path[0]; 00246 00247 if (path.size()==1) 00248 return; 00249 00250 if (path[0] != root) 00251 s += fwdsep; 00252 s += path[1]; 00253 00254 if (path.size()==2) 00255 return; 00256 00257 for (unsigned int i=2, imax=path.size(); i<imax; ++i) 00258 s += ( fwdsep + path[i] ); 00259 }
| void pathstuff::findpath | ( | bool & | found, | |
| deque< rpnprogram * > & | programlist, | |||
| vector< string > const & | path | |||
| ) |
Definition at line 450 of file pathstuff.cpp.
00455 { 00456 found = false; 00457 00458 if (path.empty()) 00459 return; 00460 00461 vector<string> v; 00462 vector<string> v2; 00463 00464 bool res; 00465 absolute(res,v,path); 00466 00467 #ifdef DEBUG_PATHSTUFF 00468 cout << "res=" << res << endl; 00469 string t; 00470 convert(t,v); 00471 cout << "..:" << t << endl; 00472 #endif 00473 00474 if (res) 00475 { 00476 /* Remove / from the front. */ 00477 v2.resize(v.end()-v.begin()-1); 00478 ::copy(v.begin()+1,v.end(),v2.begin()); 00479 00480 #ifdef DEBUG_PATHSTUFF 00481 convert(t,v2); 00482 cout << "-~ :" << t << endl; 00483 #endif 00484 00485 /* From the home directory find the path. */ 00486 findrelativetree 00487 ( 00488 found, 00489 programlist, 00490 rpnprogramstackstate().ps->back(), 00491 v2 00492 ); 00493 00494 #ifdef DEBUG_PATHSTUFF 00495 cout << "found=" << found << endl; 00496 #endif 00497 00498 } 00499 00500 }
| void pathstuff::findpath | ( | bool & | found, | |
| rpnprogram *& | prog, | |||
| vector< string > const & | path | |||
| ) |
Definition at line 363 of file pathstuff.cpp.
00368 { 00369 found = false; 00370 00371 if (path.empty()) 00372 return; 00373 00374 vector<string> v; 00375 vector<string> v2; 00376 00377 bool res; 00378 absolute(res,v,path); 00379 00380 if (res) 00381 { 00382 /* Remove / from the front. */ 00383 00384 unsigned int k(0); 00385 if (v[0]=="/") 00386 k=1; 00387 v2.resize(v.end()-v.begin()-k); 00388 ::copy(v.begin()+k,v.end(),v2.begin()); 00389 00390 00391 #ifdef DEBUG_PATHSTUFF 00392 string t; 00393 convert(t,v2); 00394 cout << "-~ :" << t << endl; 00395 #endif 00396 00397 /* From the home directory find the path. */ 00398 findrelativetree 00399 ( 00400 found, 00401 prog, 00402 &(rpnprogramstackstate().rpnhome), 00403 v2 00404 ); 00405 00406 #ifdef DEBUG_PATHSTUFF 00407 cout << "found=" << found << endl; 00408 #endif 00409 00410 } 00411 00412 }
| void pathstuff::findrelativetree | ( | bool & | found, | |
| deque< rpnprogram * > & | programlist, | |||
| rpnprogram *const | current, | |||
| vector< string > const & | pathtree | |||
| ) |
Definition at line 143 of file pathstuff.cpp.
References rpnprogram::variables, rpnvar::varname, and rpnvar::x.
00149 { 00150 found = false; 00151 programlist.clear(); 00152 programlist.push_back(current); 00153 00154 if (pathtree.empty()) 00155 { 00156 found = true; 00157 00158 return; 00159 } 00160 00161 if (!ispurerelative(pathtree)) 00162 { 00163 programlist.clear(); 00164 return; 00165 } 00166 00167 rpnprogram* p = current; 00168 rpnvar* z; 00169 00170 bool foundlocal; 00171 00172 for (unsigned int i=0, imax = pathtree.size(); i<imax; ++i) 00173 { 00174 deque<rpnvar*>& var = p->variables; 00175 if (var.empty()) 00176 return; 00177 00178 for (unsigned int k=0, kmax=var.size(); k<kmax; ++k) 00179 { 00180 z = var[k]; 00181 if (z->varname==pathtree[i]) 00182 { 00183 foundlocal = true; 00184 p = (rpnprogram*)(z->x); 00185 programlist.push_back(p); 00186 k = kmax; 00187 } 00188 } 00189 if (!foundlocal) 00190 { 00191 programlist.clear(); 00192 return; 00193 } 00194 } 00195 00196 found = true; 00197 }
| void pathstuff::findrelativetree | ( | bool & | found, | |
| rpnprogram *& | prog, | |||
| rpnprogram *const | current, | |||
| vector< string > const & | pathtree | |||
| ) |
Definition at line 59 of file pathstuff.cpp.
References rpnbase::isprogram(), rpnprogram::variables, rpnvar::varname, and rpnvar::x.
00065 { 00066 found = false; 00067 00068 if (pathtree.empty()) 00069 { 00070 prog = current; 00071 found = true; 00072 00073 return; 00074 } 00075 00076 /* Reject absolute paths. */ 00077 if (pathtree[0]==root) 00078 return; 00079 00080 /* Reject relative paths. */ 00081 bool res; 00082 contains(res,pathtree,parent); 00083 if (res) 00084 return; 00085 00086 #ifdef DEBUG_PATHSTUFF 00087 string t; 00088 convert(t,pathtree); 00089 cout << "pathtree=" << t << endl; 00090 #endif 00091 00092 rpnprogram* p = current; 00093 rpnvar* z; 00094 00095 bool foundlocal; 00096 00097 #ifdef DEBUG_PATHSTUFF 00098 cout << "found=" << found << endl; 00099 #endif 00100 00101 for (unsigned int i=0, imax = pathtree.size(); i<imax; ++i) 00102 { 00103 deque<rpnvar*>& var = p->variables; 00104 if (var.empty()) 00105 return; 00106 00107 foundlocal = false; 00108 for (unsigned int k=0, kmax=var.size(); k<kmax; ++k) 00109 { 00110 z = var[k]; 00111 00112 if ( (z->varname==pathtree[i]) && (z->x->isprogram()) ) 00113 { 00114 foundlocal = true; 00115 p = (rpnprogram*)(z->x); 00116 k = kmax; 00117 } 00118 } 00119 if (!foundlocal) 00120 return; 00121 } 00122 00123 found = true; 00124 prog = p; 00125 }
| bool const pathstuff::ispurerelative | ( | vector< string > const & | path | ) |
Definition at line 128 of file pathstuff.cpp.
References contains(), parent, and root.
00129 { 00130 if(path.empty()) 00131 return true; 00132 00133 if (path[0]==root) 00134 return false; 00135 00136 bool res; 00137 contains(res,path,parent); 00138 00139 return !res; 00140 }
| void pathstuff::pwd | ( | vector< string > & | v | ) |
Definition at line 26 of file pathstuff.cpp.
References convert().
00027 { 00028 string path; 00029 bool found(false); 00030 00031 deque<rpnprogram*> & ps( * rpnprogramstackstate().ps ); 00032 for ( unsigned int i=0; (i<ps.size())&&(!found); ++i ) 00033 { 00034 rpnprogramstackstate().findprogram( 00035 found,path,ps[i] ); 00036 } 00037 // 00038 // Replaced with for loop because the top of the 00039 // stack could be a program. 00040 // 00041 // rpnprogramstackstate().findprogram( 00042 // found,path,rpnprogramstackstate().ps->front() ); 00043 00044 if (found==false) 00045 { 00046 cout << "error:"; 00047 cout << " pathstuff::pwd( vector<string>& ) pathstuff 114"; 00048 cout << endl; 00049 cout << " found=false" << endl; 00050 } 00051 00052 //cout << "path=" << path << endl; 00053 00054 00055 convert(v,path); 00056 }
| void pathstuff::resolveparent | ( | bool & | valid, | |
| vector< string > & | path, | |||
| vector< string > const & | path0 | |||
| ) |
Definition at line 312 of file pathstuff.cpp.
00317 { 00318 valid = false; 00319 path.clear(); 00320 00321 bool res; 00322 contains(res,path0,parent); 00323 if (!res) 00324 { 00325 valid = true; 00326 path = path0; 00327 return; 00328 } 00329 00330 if (path0[0]==parent) 00331 return; 00332 00333 path.push_back( path0[0] ); 00334 00335 for (unsigned int i=1, imax=path0.size(); i<imax; ++i) 00336 { 00337 if (path0[i]==parent) 00338 { 00339 if (path.empty()) 00340 { 00341 path.clear(); 00342 return; 00343 } 00344 00345 if (path.back()==root) 00346 { 00347 path.clear(); 00348 return; 00349 } 00350 00351 path.pop_back(); 00352 } 00353 else 00354 path.push_back(path0[i]); 00355 } 00356 00357 valid = true; 00358 00359 }
string const pathstuff::fwdsep = "/" [static] |
string const pathstuff::parent = ".." [static] |
string const pathstuff::root = "/" [static] |
1.5.8