aboutsummaryrefslogtreecommitdiff
path: root/src/parse.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-08-31 06:59:47 +0000
committer_ov4 <ov4@ov4.org>2026-08-31 06:59:47 +0000
commitb48f96db8e80e1866be8b92132ece590b3a9ffb9 (patch)
treeda550823a455070e042ea3fcc7d0b053f172b8ed /src/parse.cc
parenta52c8c88cbd7c802b31cec524617161b26c5268f (diff)
parse
Diffstat (limited to 'src/parse.cc')
-rw-r--r--src/parse.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/parse.cc b/src/parse.cc
new file mode 100644
index 0000000..abb80d9
--- /dev/null
+++ b/src/parse.cc
@@ -0,0 +1,56 @@
+#include "parse.h"
+
+namespace ov4
+{
+
+int parseline(const char *cmdline, char **argv)
+{
+ static char array[MAXLINE]; /* holds local copy of command line */
+ char *buf = array; /* ptr that traverses command line */
+ char *delim; /* points to first space delimiter */
+ int argc; /* number of args */
+ int bg; /* background job? */
+
+ strcpy(buf, cmdline);
+ buf[strlen(buf)-1] = ' '; /* replace trailing '\n' with space */
+ while (*buf && (*buf == ' ')) /* ignore leading spaces */
+ buf++;
+
+ /* Build the argv list */
+ argc = 0;
+ if (*buf == '\'') {
+ buf++;
+ delim = strchr(buf, '\'');
+ }
+ else {
+ delim = strchr(buf, ' ');
+ }
+
+ while (delim) {
+ argv[argc++] = buf;
+ *delim = '\0';
+ buf = delim + 1;
+ while (*buf && (*buf == ' ')) /* ignore spaces */
+ buf++;
+
+ if (*buf == '\'') {
+ buf++;
+ delim = strchr(buf, '\'');
+ }
+ else {
+ delim = strchr(buf, ' ');
+ }
+ }
+ argv[argc] = NULL;
+
+ if (argc == 0) /* ignore blank line */
+ return 1;
+
+ /* should the job run in the background? */
+ if ((bg = (*argv[argc-1] == '&')) != 0) {
+ argv[--argc] = NULL;
+ }
+ return bg;
+}
+
+}