aboutsummaryrefslogtreecommitdiff
path: root/src/command/builtin.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-09-01 05:54:21 +0000
committer_ov4 <ov4@ov4.org>2026-09-01 05:54:21 +0000
commitf206526c58e7c116f182c4b4dc2ce4d825fd6659 (patch)
treefc5fce24565b431c4a33696bdcff589fe4dc5864 /src/command/builtin.cc
parent30726f56c8c522e81e65055ada52f56d95f68575 (diff)
refactor builtin commands
Diffstat (limited to 'src/command/builtin.cc')
-rw-r--r--src/command/builtin.cc22
1 files changed, 16 insertions, 6 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;
}