*** empty log message ***
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: execmd.cpp,v 1.1 2004-12-12 08:58:12 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: execmd.cpp,v 1.2 2004-12-14 17:54:16 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
@@ -14,6 +14,7 @@ static char rcsid[] = "@(#$Id: execmd.cpp,v 1.1 2004-12-12 08:58:12 dockes Exp $
|
||||
#include <iostream>
|
||||
|
||||
#include "execmd.h"
|
||||
#include "pathut.h"
|
||||
|
||||
using namespace std;
|
||||
#define MAX(A,B) (A>B?A:B)
|
||||
@@ -152,7 +153,7 @@ ExecCmd::doexec(const string &cmd, const list<string> args,
|
||||
}
|
||||
|
||||
// Fill up argv
|
||||
argv[0] = cmd.c_str();
|
||||
argv[0] = path_getsimple(cmd).c_str();
|
||||
i = 1;
|
||||
for (it = args.begin(); it != args.end(); it++) {
|
||||
argv[i++] = it->c_str();
|
||||
@@ -160,7 +161,7 @@ ExecCmd::doexec(const string &cmd, const list<string> args,
|
||||
argv[i] = 0;
|
||||
|
||||
#if 0
|
||||
{int i = 0;cerr << "cmd: " << cmd << endl << "ARGS:" << endl;
|
||||
{int i = 0;cerr << "cmd: " << cmd << endl << "ARGS: " << endl;
|
||||
while (argv[i]) cerr << argv[i++] << endl;}
|
||||
#endif
|
||||
|
||||
|
||||
+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;
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
#ifndef _PATHUT_H_INCLUDED_
|
||||
#define _PATHUT_H_INCLUDED_
|
||||
/* @(#$Id: pathut.h,v 1.1 2004-12-10 18:13:14 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: pathut.h,v 1.2 2004-12-14 17:54:16 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -13,6 +13,7 @@ inline void path_cat(std::string &s1, const std::string &s2) {
|
||||
s1 += s2;
|
||||
}
|
||||
|
||||
extern std::string path_getsimple(const std::string &s);
|
||||
extern std::string path_getfather(const std::string &s);
|
||||
extern std::string path_home();
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: readfile.cpp,v 1.1 2004-12-14 17:54:16 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#ifndef O_STREAMING
|
||||
#define O_STREAMING 0
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
using std::string;
|
||||
|
||||
#include "readfile.h"
|
||||
|
||||
bool file_to_string(const string &fn, string &data)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
int fd = open(fn.c_str(), O_RDONLY|O_STREAMING);
|
||||
if (fd < 0) {
|
||||
// perror("open");
|
||||
return false;
|
||||
}
|
||||
char buf[4096];
|
||||
for (;;) {
|
||||
int n = read(fd, buf, 4096);
|
||||
if (n < 0) {
|
||||
// perror("read");
|
||||
goto out;
|
||||
}
|
||||
if (n == 0)
|
||||
break;
|
||||
|
||||
try {
|
||||
data.append(buf, n);
|
||||
} catch (...) {
|
||||
// fprintf(stderr, "file_to_string: out of memory\n");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
ret = true;
|
||||
out:
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef _READFILE_H_INCLUDED_
|
||||
#define _READFILE_H_INCLUDED_
|
||||
/* @(#$Id: readfile.h,v 1.1 2004-12-14 17:54:16 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* Read whole file into string.
|
||||
* @return true for ok, false else
|
||||
*/
|
||||
bool file_to_string(const std::string &filename, std::string &data);
|
||||
|
||||
#endif /* _READFILE_H_INCLUDED_ */
|
||||
Reference in New Issue
Block a user