aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command/builtin.cc22
-rw-r--r--src/command/exit.cc2
-rw-r--r--src/command/jobs.cc2
-rw-r--r--src/command/quit.cc2
4 files changed, 19 insertions, 9 deletions
diff --git a/src/command/builtin.cc b/src/command/builtin.cc
index 3e87850..a7ba56d 100644
--- a/src/command/builtin.cc
+++ b/src/command/builtin.cc
@@ -7,6 +7,15 @@ using namespace std;
//array<string> builtin_cmd_list{"quit", "fg", "bg", "jobs"};
+unordered_map<string, function<void(char**)>> cmd =
+{
+ { "quit", ov4::command::quit },
+ { "exit", ov4::command::exit },
+ { "jobs", ov4::command::jobs },
+ { "bg", ov4::command::bg },
+ { "fg", ov4::command::fg }
+};
+
/*
* builtin_cmd - If the user has typed a built-in command then execute
* it immediately.
@@ -14,12 +23,13 @@ using namespace std;
bool exe_bultin_command(char **argv)
{
if (argv == nullptr || argv[0] == nullptr) exit(1); // WTF???
- if (strcmp(argv[0], "quit") == 0) { ov4::command::quit(); return true; }
- if (strcmp(argv[0], "exit") == 0) { ov4::command::exit(); return true; }
- if (strcmp(argv[0], "jobs") == 0) { ov4::command::jobs(); return true; }
- if (strcmp(argv[0], "bg") == 0) { ov4::command::bg(argv); return true; }
- if (strcmp(argv[0], "fg") == 0) { ov4::command::fg(argv); return true; }
- else return false;
+ string s = argv[0];
+ if (cmd.find(s) != cmd.end())
+ {
+ cmd[s](argv);
+ return true;
+ }
+ return false;
}
diff --git a/src/command/exit.cc b/src/command/exit.cc
index 5d817a6..e00a0f2 100644
--- a/src/command/exit.cc
+++ b/src/command/exit.cc
@@ -3,7 +3,7 @@
namespace ov4::command
{
-void exit()
+void exit(char **argv)
{
std::exit(0);
}
diff --git a/src/command/jobs.cc b/src/command/jobs.cc
index f618d55..ccdda75 100644
--- a/src/command/jobs.cc
+++ b/src/command/jobs.cc
@@ -7,7 +7,7 @@ namespace ov4::command
using namespace ov4;
-void jobs()
+void jobs(char **argv)
{
listjobs(ov4::jobs);
}
diff --git a/src/command/quit.cc b/src/command/quit.cc
index 8aee14d..0ac918b 100644
--- a/src/command/quit.cc
+++ b/src/command/quit.cc
@@ -5,7 +5,7 @@ namespace ov4::command
using namespace ov4;
-void quit()
+void quit(char **argv)
{
std::exit(0);
}