*** empty log message ***
This commit is contained in:
+22
-3
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: pathut.cpp,v 1.1 2004-12-10 18:13:14 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: pathut.cpp,v 1.2 2004-12-14 17:54:16 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#ifndef TEST_PATHUT
|
||||
@@ -31,6 +31,20 @@ std::string path_getfather(const std::string &s) {
|
||||
return father;
|
||||
}
|
||||
|
||||
std::string path_getsimple(const std::string &s) {
|
||||
std::string simple = s;
|
||||
|
||||
if (simple.empty())
|
||||
return simple;
|
||||
|
||||
std::string::size_type slp = simple.rfind('/');
|
||||
if (slp == std::string::npos)
|
||||
return simple;
|
||||
|
||||
simple.erase(0, slp+1);
|
||||
return simple;
|
||||
}
|
||||
|
||||
std::string path_home()
|
||||
{
|
||||
uid_t uid = getuid();
|
||||
@@ -53,13 +67,18 @@ using namespace std;
|
||||
|
||||
const char *tstvec[] = {"", "/", "/dir", "/dir/", "/dir1/dir2",
|
||||
"/dir1/dir2",
|
||||
"./dir", "./dir1/", "dir", "../dir"};
|
||||
"./dir", "./dir1/", "dir", "../dir", "/dir/toto.c",
|
||||
"/dir/.c",
|
||||
};
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
|
||||
for (int i = 0;i < sizeof(tstvec) / sizeof(char *); i++) {
|
||||
cout << tstvec[i] << " -> " << path_getfather(tstvec[i]) << endl;
|
||||
cout << tstvec[i] << " FATHER " << path_getfather(tstvec[i]) << endl;
|
||||
}
|
||||
for (int i = 0;i < sizeof(tstvec) / sizeof(char *); i++) {
|
||||
cout << tstvec[i] << " SIMPLE " << path_getsimple(tstvec[i]) << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user