aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--include/option.h4
-rw-r--r--include/util/io.h1
-rw-r--r--include/util/option_parse.h2
-rw-r--r--src/option.cc34
-rw-r--r--src/util/io.cc14
6 files changed, 42 insertions, 15 deletions
diff --git a/README.md b/README.md
index 96092a6..e51f9b4 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,8 @@ NO AI/Codex/Claude Code/Antigravity
Only the very traditional methods (stack overflow, man, cpp reference, etc.) are used
+Very simple and boring things (just job CRUD, really) are copied from CS:APP (I did that lab and now am lazy, so they're here), but will be refactored soon
+
## Build
```sh
diff --git a/include/option.h b/include/option.h
index b089012..b939a8a 100644
--- a/include/option.h
+++ b/include/option.h
@@ -7,4 +7,8 @@ namespace ov4::option
void v(std::string s);
+void p(std::string s);
+
+void h(std::string s);
+
}
diff --git a/include/util/io.h b/include/util/io.h
index 4f55fec..6fb2a29 100644
--- a/include/util/io.h
+++ b/include/util/io.h
@@ -98,7 +98,6 @@ void safe_output(T x, T_arg ...arg)
errno = errno_old;
}
-void usage(void);
void unix_error(const char *msg);
void app_error(const char *msg);
diff --git a/include/util/option_parse.h b/include/util/option_parse.h
index c68c549..7e362e2 100644
--- a/include/util/option_parse.h
+++ b/include/util/option_parse.h
@@ -13,6 +13,8 @@ namespace ov4
inline const std::unordered_map<std::string, std::function<void(std::string s)>> option_list =
{
{"-v", ov4::option::v},
+ {"-h", ov4::option::h},
+ {"-p", ov4::option::p},
};
void exe_option(char **c_argv);
diff --git a/src/option.cc b/src/option.cc
index 552d83f..2cae4ef 100644
--- a/src/option.cc
+++ b/src/option.cc
@@ -5,6 +5,7 @@
#include "global.h"
#include "util/io.h"
+#include "util/prompt.h"
using namespace std;
@@ -27,6 +28,37 @@ void v(string s)
}
LOG << "-v: invalid value" << endl;
}
-
+
+void p(string s)
+{
+ if (s == "" || s == "true" || s == "1")
+ {
+ ov4::emit_prompt = true;
+ LOG << "emit_prompt = true" << endl;
+ return;
+ }
+ if (s == "false" || s == "0")
+ {
+ ov4::emit_prompt = false;
+ LOG << "emit_prompt = flase" << endl;
+ return;
+ }
+ LOG << "-p: invalid value" << endl;
+}
+
+
+/*
+ * usage - print a help message
+ */
+void h([[maybe_unused]] string s)
+{
+ cout << "\
+Usage: ccshell [-hvp] \n\
+ -h print this message \n\
+ -v(=<bool>) print additional diagnostic information \n\
+ -p(=<bool>) do not emit a command prompt \
+" << endl;
+ exit(1);
}
+}
diff --git a/src/util/io.cc b/src/util/io.cc
index 09479e6..e1960ae 100644
--- a/src/util/io.cc
+++ b/src/util/io.cc
@@ -130,7 +130,7 @@ void wrap_eliminator(char *s, char replacement)
s[i] = replacement;
}
-void write_helper(const char *s)
+void _write_helper(const char *s)
{
int errno_old = errno;
@@ -142,18 +142,6 @@ void write_helper(const char *s)
}
/*
- * usage - print a help message
- */
-void usage(void)
-{
- printf("Usage: shell [-hvp]\n");
- printf(" -h print this message\n");
- printf(" -v print additional diagnostic information\n");
- printf(" -p do not emit a command prompt\n");
- exit(1);
-}
-
-/*
* unix_error - unix-style error routine
*/
void unix_error(const char *msg)