mirror of
https://github.com/ksherlock/mpw-shell.git
synced 2024-12-29 15:29:19 +00:00
which command
This commit is contained in:
parent
446e3e5e1e
commit
50f171d5c8
@ -12,6 +12,9 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
|
#include "cxx/string_splitter.h"
|
||||||
|
#include "cxx/filesystem.h"
|
||||||
|
|
||||||
//MAXPATHLEN
|
//MAXPATHLEN
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
@ -21,6 +24,9 @@ namespace ToolBox {
|
|||||||
std::string UnixToMac(const std::string path);
|
std::string UnixToMac(const std::string path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace fs = filesystem;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -16,6 +16,7 @@ int builtin_set(Environment &e, const std::vector<std::string> &, const fdmask &
|
|||||||
int builtin_unset(Environment &e, const std::vector<std::string> &, const fdmask &);
|
int builtin_unset(Environment &e, const std::vector<std::string> &, const fdmask &);
|
||||||
int builtin_export(Environment &e, const std::vector<std::string> &, const fdmask &);
|
int builtin_export(Environment &e, const std::vector<std::string> &, const fdmask &);
|
||||||
int builtin_unexport(Environment &e, const std::vector<std::string> &, const fdmask &);
|
int builtin_unexport(Environment &e, const std::vector<std::string> &, const fdmask &);
|
||||||
|
int builtin_which(Environment &e, const std::vector<std::string> &, const fdmask &);
|
||||||
|
|
||||||
int builtin_evaluate(Environment &e, std::vector<token> &&, const fdmask &);
|
int builtin_evaluate(Environment &e, std::vector<token> &&, const fdmask &);
|
||||||
|
|
||||||
|
30
command.cpp
30
command.cpp
@ -12,6 +12,8 @@
|
|||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include "cxx/filesystem.h"
|
||||||
|
#include "cxx/string_splitter.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -19,6 +21,34 @@
|
|||||||
|
|
||||||
extern volatile int control_c;
|
extern volatile int control_c;
|
||||||
|
|
||||||
|
namespace fs = filesystem;
|
||||||
|
extern fs::path mpw_path();
|
||||||
|
|
||||||
|
namespace ToolBox {
|
||||||
|
std::string MacToUnix(const std::string path);
|
||||||
|
std::string UnixToMac(const std::string path);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::path which(const Environment &env, const std::string &name) {
|
||||||
|
std::error_code ec;
|
||||||
|
|
||||||
|
if (name.find_first_of("/:") != name.npos) {
|
||||||
|
// canonical?
|
||||||
|
fs::path p(name);
|
||||||
|
if (fs::exists(p, ec)) return name;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string s = env.get("commands");
|
||||||
|
for (string_splitter ss(s, ','); ss; ++ss) {
|
||||||
|
fs::path p(ToolBox::MacToUnix(*ss));
|
||||||
|
p /= name;
|
||||||
|
if (fs::exists(p, ec)) return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
// error..
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
void launch_mpw(const Environment &env, const std::vector<std::string> &argv, const fdmask &fds) {
|
void launch_mpw(const Environment &env, const std::vector<std::string> &argv, const fdmask &fds) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user