aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cc10
-rw-r--r--src/util/string.cc38
2 files changed, 41 insertions, 7 deletions
diff --git a/src/main.cc b/src/main.cc
index 04aca2a..d7719b2 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -18,6 +18,8 @@
#include "ground.h"
#include "eval.h"
#include "path.h"
+#include "util/string.h"
+#include "test.h"
using namespace std;
using namespace ov4;
@@ -43,12 +45,6 @@ handler_t *Signal(int signum, handler_t *handler);
// built-in commands
void builtin_command_quit();
-void test()
-{
- cout << find_cmd("ls") << endl;
- exit(0);
-}
-
/*
* main - The shell's main routine
*/
@@ -59,7 +55,7 @@ You are using ccshell. \n\
This is free software; see the source for copying conditions. \
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. \n\
Published under GNU AFFERO GENERAL PUBLIC LICENSE (AGPL) Version 3." << endl;
- //test();
+ //test(argv);
init();
char c;
char cmdline[MAXLINE];
diff --git a/src/util/string.cc b/src/util/string.cc
new file mode 100644
index 0000000..8c6c86a
--- /dev/null
+++ b/src/util/string.cc
@@ -0,0 +1,38 @@
+#include "util/string.h"
+
+namespace ov4
+{
+
+using namespace std;
+
+void string2argv(const vector<string> * const s, char **argv)
+{
+
+ // pointers [0, size)
+ // nullptr [size]
+ // data [size+1, ...)
+
+ char *p = (char*)(argv + s->size() + 1);
+
+ argv[s->size()] = nullptr;
+
+ for (size_t i = 0; i < s->size(); i++)
+ {
+ strcpy(p, (*s)[i].c_str());
+ argv[i] = p;
+ p += (*s)[i].size() + 1; // for '\0'
+ }
+}
+
+void argv2string(vector<string> *s, const char * const * argv)
+{
+ if (argv == nullptr) return;
+
+ for (size_t i = 0; true; i++)
+ {
+ if (argv[i] == nullptr) return;
+ s->push_back(argv[i]);
+ }
+}
+
+}