diff options
| author | _ov4 <ov4@ov4.org> | 2026-08-31 06:59:47 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-08-31 06:59:47 +0000 |
| commit | b48f96db8e80e1866be8b92132ece590b3a9ffb9 (patch) | |
| tree | da550823a455070e042ea3fcc7d0b053f172b8ed | |
| parent | a52c8c88cbd7c802b31cec524617161b26c5268f (diff) | |
parse
| -rw-r--r-- | include/global.h | 11 | ||||
| -rw-r--r-- | include/job.h | 4 | ||||
| -rw-r--r-- | include/parse.h | 13 | ||||
| -rw-r--r-- | include/setting.h | 8 | ||||
| -rw-r--r-- | include/util.h | 2 | ||||
| -rw-r--r-- | src/global.cc (renamed from src/setting.cc) | 2 | ||||
| -rw-r--r-- | src/main.cc | 51 | ||||
| -rw-r--r-- | src/parse.cc | 56 |
8 files changed, 84 insertions, 63 deletions
diff --git a/include/global.h b/include/global.h new file mode 100644 index 0000000..ee1141e --- /dev/null +++ b/include/global.h @@ -0,0 +1,11 @@ +#pragma once + +namespace ov4 +{ +extern int verbose; + +constexpr int MAXLINE = 1024; +constexpr int MAXARGS = 128; + + +} diff --git a/include/job.h b/include/job.h index cbd9b30..e94bda6 100644 --- a/include/job.h +++ b/include/job.h @@ -10,10 +10,8 @@ #include <sys/wait.h> #include <errno.h> -#include "setting.h" +#include "global.h" -#define MAXLINE 1024 /* max line size */ -#define MAXARGS 128 /* max args on a command line */ #define MAXJOBS 16 /* max jobs at any point in time */ #define MAXJID 1<<16 /* max job ID */ diff --git a/include/parse.h b/include/parse.h new file mode 100644 index 0000000..8fdbe12 --- /dev/null +++ b/include/parse.h @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#include "global.h" + +namespace ov4 +{ + +int parseline(const char *cmdline, char **argv); + +} diff --git a/include/setting.h b/include/setting.h deleted file mode 100644 index ec4f08b..0000000 --- a/include/setting.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -namespace ov4 -{ - -extern int verbose; - -} diff --git a/include/util.h b/include/util.h index 8df2b7f..dd51fff 100644 --- a/include/util.h +++ b/include/util.h @@ -13,7 +13,7 @@ #include <vector> #include <string> -#include "setting.h" +#include "global.h" #define LOG !(ov4::GLOBAL_DEBUG && verbose) ? (void)0 : ov4::LogVoidify() & std::clog diff --git a/src/setting.cc b/src/global.cc index 0461c16..e2a17ab 100644 --- a/src/setting.cc +++ b/src/global.cc @@ -1,4 +1,4 @@ -#include "setting.h" +#include "global.h" namespace ov4 { diff --git a/src/main.cc b/src/main.cc index 22395fb..ffcf52d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -18,6 +18,7 @@ #include "util.h" #include "job.h" +#include "parse.h" using namespace std; using namespace ov4; @@ -66,8 +67,6 @@ void sigchld_handler(int sig); void sigtstp_handler(int sig); void sigint_handler(int sig); -/* Here are helper routines that we've provided for you */ -int parseline(const char *cmdline, char **argv); void sigquit_handler(int sig); @@ -233,55 +232,7 @@ void eval(char *cmdline) * argument. Return true if the user has requested a BG job, false if * the user has requested a FG job. */ -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; -} /* * builtin_cmd - If the user has typed a built-in command then execute 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; +} + +} |
