aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-09-01 00:39:44 +0000
committer_ov4 <ov4@ov4.org>2026-09-01 00:39:44 +0000
commit5e94ca9f060d2952ef08913234c500a815f734bf (patch)
tree169e6c67289b70753aa76edb818f3b1f63112884
parent54261d62d47624e9ff4724c42aaa05eaf478e606 (diff)
refactor
-rw-r--r--include/command/builtin.h23
-rw-r--r--include/eval.h3
-rw-r--r--include/global.h3
-rw-r--r--include/ground.h2
-rw-r--r--include/handler.h2
-rw-r--r--include/util/io.h (renamed from include/util.h)16
-rw-r--r--src/command/builtin.cc23
-rw-r--r--src/command/quit.cc13
-rw-r--r--src/eval.cc21
-rw-r--r--src/global.cc1
-rw-r--r--src/main.cc2
-rw-r--r--src/util/io.cc (renamed from src/util.cc)21
12 files changed, 85 insertions, 45 deletions
diff --git a/include/command/builtin.h b/include/command/builtin.h
new file mode 100644
index 0000000..f37b844
--- /dev/null
+++ b/include/command/builtin.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <string>
+#include <vector>
+#include <array>
+#include <cstring>
+#include <iostream>
+
+namespace ov4
+{
+
+extern std::vector<std::string> builtin_cmd_list;
+
+bool exe_bultin_command(char **argv);
+
+}
+
+namespace ov4::command
+{
+
+void quit();
+
+}
diff --git a/include/eval.h b/include/eval.h
index a6157e0..919d03f 100644
--- a/include/eval.h
+++ b/include/eval.h
@@ -14,7 +14,8 @@
#include <string>
#include "global.h"
-#include "util.h"
+#include "util/io.h"
+#include "command/builtin.h"
#include "job.h"
#include "ground.h"
#include "parse.h"
diff --git a/include/global.h b/include/global.h
index 7d63c1b..5ff04f3 100644
--- a/include/global.h
+++ b/include/global.h
@@ -11,6 +11,7 @@ extern int verbose;
constexpr int MAXLINE = 1024;
constexpr int MAXARGS = 128;
-extern std::vector<std::string> builtin_cmd_list;
+
+constexpr bool GLOBAL_DEBUG = true;
}
diff --git a/include/ground.h b/include/ground.h
index 564e6ab..d57f085 100644
--- a/include/ground.h
+++ b/include/ground.h
@@ -6,7 +6,7 @@
#include <string.h>
#include "global.h"
-#include "util.h"
+#include "util/io.h"
#include "job.h"
#include "handler.h"
diff --git a/include/handler.h b/include/handler.h
index 23c9540..f226387 100644
--- a/include/handler.h
+++ b/include/handler.h
@@ -12,7 +12,7 @@
#include <sys/wait.h>
#include <errno.h>
-#include "util.h"
+#include "util/io.h"
#include "job.h"
namespace ov4
diff --git a/include/util.h b/include/util/io.h
index bab7738..5bdbcbd 100644
--- a/include/util.h
+++ b/include/util/io.h
@@ -17,7 +17,13 @@
#define LOG !(ov4::GLOBAL_DEBUG && verbose) ? (void)0 : ov4::LogVoidify() & std::clog
-namespace ov4 {
+namespace ov4
+{
+
+struct LogVoidify { void operator&(std::ostream&) const {} };
+
+constexpr int DECIMAL = 10;
+constexpr int LENGTH = 32;
void atomic_print(char *s, bool ignore_wrap = false);
void atomic_print(int x);
@@ -26,13 +32,5 @@ void atomic_debug(int x);
bool isnum(char *s);
void reverse(char str[], int length);
char *itoa(int num, char* str, int base);
-int builtin_cmd(char *c_str);
-void builtin_command_quit();
-
-constexpr bool GLOBAL_DEBUG = true;
-struct LogVoidify { void operator&(std::ostream&) const {} };
-
-constexpr int DECIMAL = 10;
-constexpr int LENGTH = 32;
}
diff --git a/src/command/builtin.cc b/src/command/builtin.cc
new file mode 100644
index 0000000..b2c3149
--- /dev/null
+++ b/src/command/builtin.cc
@@ -0,0 +1,23 @@
+#include "command/builtin.h"
+
+namespace ov4
+{
+
+using namespace std;
+
+//array<string> builtin_cmd_list{"quit", "fg", "bg", "jobs"};
+
+/*
+ * builtin_cmd - If the user has typed a built-in command then execute
+ * it immediately.
+ */
+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; }
+ else return false;
+}
+
+
+
+}
diff --git a/src/command/quit.cc b/src/command/quit.cc
new file mode 100644
index 0000000..917f642
--- /dev/null
+++ b/src/command/quit.cc
@@ -0,0 +1,13 @@
+#include "command/builtin.h"
+
+namespace ov4::command
+{
+
+using namespace ov4;
+
+void quit()
+{
+ exit(0);
+}
+
+}
diff --git a/src/eval.cc b/src/eval.cc
index 4350367..1b5884f 100644
--- a/src/eval.cc
+++ b/src/eval.cc
@@ -27,17 +27,18 @@ void eval(char *cmdline)
int ground = parseline(cmdline, argv);
if (argv[0] == nullptr) return;
+ if (exe_bultin_command(argv)) return;
- if (builtin_cmd(argv[0]))
- {
- LOG << "built-in" << endl;
- if (strcmp(argv[0], "quit") == 0) builtin_command_quit();
- else if (strcmp(argv[0], "jobs") == 0) listjobs(jobs);
- else if (strcmp(argv[0], "fg") == 0) do_bgfg(argv);
- else if (strcmp(argv[0], "bg") == 0) do_bgfg(argv);
- else cerr << "built-in but not supported" << endl;
- return;
- }
+ // if (builtin_cmd(argv[0]))
+ // {
+ // LOG << "built-in" << endl;
+ // if (strcmp(argv[0], "quit") == 0) builtin_command_quit();
+ // else if (strcmp(argv[0], "jobs") == 0) listjobs(jobs);
+ // else if (strcmp(argv[0], "fg") == 0) do_bgfg(argv);
+ // else if (strcmp(argv[0], "bg") == 0) do_bgfg(argv);
+ // else cerr << "built-in but not supported" << endl;
+ // return;
+ // }
sigset_t prev;
block_all(&prev);
diff --git a/src/global.cc b/src/global.cc
index 5b92331..0995b4d 100644
--- a/src/global.cc
+++ b/src/global.cc
@@ -6,6 +6,5 @@ namespace ov4
using namespace std;
int verbose = 0;
-vector<string> builtin_cmd_list = {"quit", "fg", "bg", "jobs"};
}
diff --git a/src/main.cc b/src/main.cc
index f75dc7d..04aca2a 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -11,7 +11,7 @@
#include <vector>
#include <string>
-#include "util.h"
+#include "util/io.h"
#include "job.h"
#include "parse.h"
#include "handler.h"
diff --git a/src/util.cc b/src/util/io.cc
index 9574ce6..531bd47 100644
--- a/src/util.cc
+++ b/src/util/io.cc
@@ -1,4 +1,4 @@
-#include "util.h"
+#include "util/io.h"
namespace ov4
{
@@ -96,23 +96,4 @@ char *itoa(int num, char* str, int base)
return str;
}
-/*
- * builtin_cmd - If the user has typed a built-in command then execute
- * it immediately.
- */
-int builtin_cmd(char *c_str)
-{
- string s(c_str);
- for (auto c : builtin_cmd_list)
- if (c == s)
- return 1;
- return 0; /* not a builtin command */
-}
-
-void builtin_command_quit()
-{
- exit(0);
-}
-
-
}