00001 // ======================================================================== // 00002 // // 00003 // File : path.cpp // 00004 // Purpose : // 00005 // Time-stamp: <Thu May/09/2002 00:48 MET Coder@ReallySoft.de> // 00006 // // 00007 // (C) May 2002 by Ralf Westram // 00008 // // 00009 // Permission to use, copy, modify, distribute and sell this software // 00010 // and its documentation for any purpose is hereby granted without fee, // 00011 // provided that the above copyright notice appear in all copies and // 00012 // that both that copyright notice and this permission notice appear // 00013 // in supporting documentation. // 00014 // // 00015 // Ralf Westram makes no representations about the suitability of this // 00016 // software for any purpose. It is provided "as is" without express or // 00017 // implied warranty. // 00018 // // 00019 // ======================================================================== // 00020 00021 #include "path.h" 00022 00023 #include <algorithm> 00024 00025 00026 using namespace std; 00027 using namespace rs; 00028 using namespace rs::sys_dep; 00029 00030 // start of implementation of class Path: 00031 00032 // --------------------- 00033 // Path::Path() 00034 // --------------------- 00035 Path::Path() 00036 { 00037 const char *path = getenv("PATH"); 00038 init(path); 00039 } 00040 00041 // ------------------------------------- 00042 // Path::Path(const char *path) 00043 // ------------------------------------- 00044 Path::Path(const char *path) 00045 { 00046 init(path); 00047 } 00048 00049 struct str_empty { bool operator()(const string& s) { return s.empty(); } }; 00050 00051 // ------------------------------------------ 00052 // void Path::init(const char *path) 00053 // ------------------------------------------ 00054 void Path::init(const char *path) 00055 { 00056 dirs.clear(); 00057 00058 const char *start = path; 00059 char delimiter = strchr(start, ';') ? ';' : ':'; 00060 00061 while (1) { 00062 const char *sep = strchr(start, delimiter); 00063 if (!sep) break; 00064 dirs.push_back(string(start, sep-start)); 00065 start = sep+1; 00066 } 00067 dirs.push_back(start); 00068 00069 // cout << "Dirs[1]:\n"; copy(dirs.begin(), dirs.end(), ostream_iterator<string>(cout, "\n")); 00070 00071 // remove empty directories from path : 00072 dirs.erase(remove_if(dirs.begin(), dirs.end(), str_empty()), dirs.end()); 00073 } 00074 00075 // -end- of implementation of class Path. 00076
Contact me in case of errors or questions. This documentation is powered by . |
(C) 2000-2002 |