diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/command/cd.cc | 37 | ||||
| -rw-r--r-- | src/eval.cc | 6 | ||||
| -rw-r--r-- | src/global.cc | 2 | ||||
| -rw-r--r-- | src/ground.cc | 4 | ||||
| -rw-r--r-- | src/init.cc | 4 | ||||
| -rw-r--r-- | src/path.cc | 2 | ||||
| -rw-r--r-- | src/util/io.cc | 4 | ||||
| -rw-r--r-- | src/util/prompt.cc | 3 | ||||
| -rw-r--r-- | src/util/string.cc | 4 |
9 files changed, 48 insertions, 18 deletions
diff --git a/src/command/cd.cc b/src/command/cd.cc index 49b1899..5434f20 100644 --- a/src/command/cd.cc +++ b/src/command/cd.cc @@ -1,10 +1,32 @@ #include "command/builtin.h" -namespace ov4::command -{ +#include <cerrno> +#include <unordered_map> using namespace std; +// constexpr string_view +// err_EACCES = "cd: Search permission is denied for one of the components of path.", +// err_EFAULT = "cd: path points outside your accessible address space.", +// err_EIO = "An I/O error occurred.", +// err_ENOTDIR = "A component of path is not a directory.", +// err_ENOENT = "The directory specified in path does not exist.", +// err_ENAMETOOLONG = "path is too long.", +// err_ENOMEM = "Insufficient kernel memory was available."; + +const unordered_map<int, string_view> err_list = { + { EACCES, "cd: Search permission is denied for one of the components of path." }, + { EFAULT, "cd: path points outside your accessible address space." }, + { EIO, "An I/O error occurred." }, + { ENOTDIR, "A component of path is not a directory." }, + { ENOENT, "The directory specified in path does not exist." }, + { ENAMETOOLONG, "path is too long." }, + { ENOMEM, "Insufficient kernel memory was available."}, +}; + +namespace ov4::command +{ + void cd(char **argv) { if (argv == nullptr) return; @@ -13,7 +35,16 @@ void cd(char **argv) cout << "cd: requires path" << endl; return; } - ov4::set_current_dir(argv[1]); + int ret = ov4::set_current_dir(argv[1]); + if (ret != 0) + { + if (err_list.find(errno) != err_list.end()) + { + cout << "cd: " << err_list.at(errno) << endl; + return; + } + cout << "cd: Error occured, code: " << errno << endl; + } } } diff --git a/src/eval.cc b/src/eval.cc index b700c21..4f293c7 100644 --- a/src/eval.cc +++ b/src/eval.cc @@ -1,10 +1,10 @@ #include "eval.h" -namespace ov4 -{ - using namespace std; +namespace ov4 +{ + /* * eval - Evaluate the command line that the user has just typed in * diff --git a/src/global.cc b/src/global.cc index 0995b4d..e2a17ab 100644 --- a/src/global.cc +++ b/src/global.cc @@ -3,8 +3,6 @@ namespace ov4 { -using namespace std; - int verbose = 0; } diff --git a/src/ground.cc b/src/ground.cc index 2047ebf..54a333f 100644 --- a/src/ground.cc +++ b/src/ground.cc @@ -1,10 +1,10 @@ #include "ground.h" +using namespace std; + namespace ov4 { -using namespace std; - /* * waitfg - Block until process pid is no longer the foreground process */ diff --git a/src/init.cc b/src/init.cc index e4d0b8f..5f6e325 100644 --- a/src/init.cc +++ b/src/init.cc @@ -1,10 +1,10 @@ #include "init.h" +using namespace std; + namespace ov4 { -using namespace std; - void init() { cout << "\ diff --git a/src/path.cc b/src/path.cc index 4d2ea1b..6feabee 100644 --- a/src/path.cc +++ b/src/path.cc @@ -39,7 +39,7 @@ string find_cmd(const string &s) } } -string path_unifier(const string &s) +string path_unifier(const string &s, bool is_cmd) { if (s.size() == 0) return ""; if (s[0] == '/') return s; diff --git a/src/util/io.cc b/src/util/io.cc index 1261684..4a094d0 100644 --- a/src/util/io.cc +++ b/src/util/io.cc @@ -1,10 +1,10 @@ #include "util/io.h" +using namespace std; + namespace ov4 { -using namespace std; - void atomic_print(char *s, bool ignore_wrap) { if (ignore_wrap) diff --git a/src/util/prompt.cc b/src/util/prompt.cc index 977cb0b..ac9137b 100644 --- a/src/util/prompt.cc +++ b/src/util/prompt.cc @@ -1,8 +1,9 @@ #include "util/prompt.h" +using namespace std; + namespace ov4 { - using namespace std; bool emit_prompt = true; /* emit prompt (default) */ diff --git a/src/util/string.cc b/src/util/string.cc index 8c6c86a..7146fe3 100644 --- a/src/util/string.cc +++ b/src/util/string.cc @@ -1,10 +1,10 @@ #include "util/string.h" +using namespace std; + namespace ov4 { -using namespace std; - void string2argv(const vector<string> * const s, char **argv) { |
